PHP : Thumbnail Generator

3 Mar

<?php
$thumb_dir = “thumb”; //The directory where you want your thumbs to be…
$dh = opendir(“.”); //The directory where the full sized images are…
while ($f = readdir( $dh ) ) {
echo call_user_func (‘makethumb’, $f);
}

function makethumb($file)
{

if(eregi(“.(jpg|jpeg)$”,$file))
if (!file_exists(“$thumb_dir/$file”)) { //is it there already? Lets check & find out…
$src = ImageCreateFromJPEG($file);

$filesize = filesize($file);
$org_h = imagesy($src);
$org_w = imagesx($src);

print “Original Size (<b>W</b>x<b>H</b>): <b>$org_w</b>x<b>$org_h</b> >> “;

if ($org_h > $org_w) {
$height = 72; //The max size of the thumbnail…
$width = floor ($height * $org_w / $org_h);
} else {
$width = 96;
$height = floor ($width * $org_h / $org_w);
}

$img = ImageCreate($width,$height);

ImageCopyResized ($img, $src, 0, 0, 0, 0, $width, $height, $org_w, $org_h );

ImageJPEG($img, “$thumb_dir/$file”, 75);
print “The file <b>$file</b> has been copied and resized.<br>”;

ImageDestroy ($img);
ImageDestroy ($src);
} else print “The file <b>$file</b> exists already.<br>”;

}

?>

http://www.oxyscripts.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: