Hey there, I’ve got a folder with about 150 pictures in it which are quite large. Since I don’t really want to go through each one separately and make thumbnails of each, I want to make a sort of one-time script that will go through the entire folder and create a smaller thumbnail of each picture. I’ve got most of it down, but I’m just not sure how to resize it.
[php]<?php
header(“Content-type: image/jpeg”);
if($handle = opendir(’…/pics’)){
while(false !== ($file = readdir($handle))){
if(is_file($file) && $file != “cleanup.php”){
$pics[] = $file;
}
}
closedir($handle);
}
$num = count($pics);
for($i = 0; $i <= ($num - 1); $i++){
$size = getimagesize($pics[$i]);
if($size[0] > 200){
$width = 200;
$factor = $size[0] / $width;
$height = $size[1] / $factor;
}
elseif($size[1] > 150){
$height = 150;
$factor = $size[1] / $height;
$width = $size[0] / $factor;
} else {
$width = $size[0];
$height = $size[1];
}
$image = imagecreatefromjpeg($pics[$i]);
imagejpeg($image);
}
?>[/php]
As you can see, the script puts all the image names into an array (which I’m going to use for some other stuff later), and then goes through that array and figures out the width and height for each (I also want to keep the the image size ratio, basically keeping the images 200x150 or smaller, but I don’t want distorted thumbnails). And then here’s where I get lost. I don’t exactly want to create an image to display, I want to create an actual file without displaying it if possible - but I don’t know how to resize it to $width and $height. Can anyone help me? Thanks in advance.