Mein Problem ist, dass ich von PHP keinen Schimmer habe und es in manchen Belangen anders funktioniert wie C++ =). Und Google hilft nunmal nicht, wenn man nicht weiß wonach man suchen soll.
Ich habe es immerhin geschafft das Script mit einer while-Schleife auszustatten und dennoch hängt es sich fröhlich daran auf.
---------------
PHP-Code:
$string="";
$fileCount=0;
$filePath=$PATH.'imagesdb/full/'; # Specify the path you want to look in.
$dir = opendir($filePath); # Open the path
while ($file = readdir($dir)) {
if (eregi(".jpg",$file) && !eregi("._",$file) ) {# Look at only files with a .jpg extension
$image_name = "$file";
}
}
$style = "thumb";
// I've taken the foldernames. It's easier. For the
//thumbnails replace "show" with "thumb".
$file_compare = "imagesdb/$style/$image_name";
if(!file_exists($file_compare)){
switch($style) {
case "show":
$max_size = 800;
break;
case "thumb":
$max_size = 125;
}
$dest_file = "imagesdb/$style/$image_name";
// set output file
$image_file = "imagesdb/full/$image_name";
// set source file
$size = getimagesize($image_file);
// get original size
if($size[0] > $size[1]) {
$divisor = $size[0] / $max_size;
}
else {
$divisor = $size[1] / $max_size;
}
// to get allways pictures of the same size, which ist
// mostly wanted in imageviewers, look what ist larger:
// width or height
$new_width = $size[0] / $divisor;
$new_height = $size[1] / $divisor;
// set new sizes
settype($new_width, 'integer');
settype($new_height, 'integer');
// sizes should be integers
$image_big = imagecreatefromjpeg($image_file);
// load original image
$image_small = imagecreatetruecolor($new_width, $new_height);
// create new image
imagecopyresampled($image_small, $image_big, 0,0, 0,0, $new_width,$new_height, $size[0],$size[1]);
// imageresampled whill result in a much higher quality
// than imageresized
imagedestroy($image_big);
// the original data are no longer used
header("Content-type: image/jpeg");
if($style=="show" || $style=="thumb") {
if(!file_exists($dest_file))
imagejpeg($image_small, $dest_file, 100);
}
// if you have set additional sizese put them in the
// if-arguments, too.
// if someone calls the image.php directly in the
// browser with imagenames allready existing, they
// won't be overwritten
imagejpeg($image_small, '', 100);
imagedestroy($image_small);
// finally send image to browser and destroy no longer
// needed data.
$fileCount++;
}
else {
echo "Nothing to convert!";
}
Vielleicht findet ja von euch wer den Fehler -> es kommt stets nur 1 Bild, danach ist Schluß. Und ich habe noch ein Problem: bei Bildern mit mehreren mb sagt er mir, dass ich irgendeine Speichergrenze mit 500kb überschritten habe ...