making thumbnails

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. :)

for a premade script check out
http://www.hotscripts.com/PHP/Scripts_a … ipulation/

And on a google (php images resize) found these
http://www.sitepoint.com/article/1058
http://www.webmasterworld.com/forum88/3639.htm

Well, the Google links didn’t really help - the first one told me what I already knew, because I don’t want to simply resize it in the tag, I want to actually create a new image with the new dimensions. The second link wanted me to pay for subscription, so I wasn’t going to bother with that. Anyways the hotscripts should help, I’ve taken some code from in there, that should do the trick. Thanks for the help. :)

Sponsor our Newsletter | Privacy Policy | Terms of Service