<?php
$factor = 4;
$base_dir = "images";
if ($dir = opendir($base_dir)) {
while (false !== ($file = readdir($dir))) {
$read_dir = "$base_dir/$file";
if ($file != "." && $file != ".." && !preg_match("/(.*?)thumbnail_(.*?)/si", $file)) {
$image_info = getimagesize($read_dir);
$image_info[0] = $image_info[0]/$factor;
$image_info[1] = $image_info[1]/$factor;
$image_org = imagecreatefromjpeg ($file);
$new_thumbnail = imagecreatetruecolor ($image_info[0], $image_info[1]);
imagecopyresized ($new_thumbnail, $image_org, 0, 0, 0, 0, $image_info[0], $image_info[1], imagesx($image_org), imagesy($image_org));
$new_file_name = "thumbnail_" . $file;
imagejpeg($new_thumbnail, $base_dir."/".$new_file_name, 85);
imagedestroy ($new_thumbnail);
echo "<p>Succes!";
}
}
}
?>
I'm trying to make a script that loops through a directory and checks if there isn't made a thumbnail of a picture. If so it should create a thumbnail. It does create a thumbnail, but it the thumbnail is just plain black. Any help would be appreciated.