Automatically create thumbnails of JPG images to your required size. Great for creating a thumbnail of an image automatically when a user uploads a 2.5MB 3500x2500 picture and you want to have a thumbnail on the website of a specific dimension. This version only does JPGs.
<?php
function thumbnail($i,$nw,$p,$nn) {
$img=imagecreatefromjpeg("$i");
$ow=imagesx($img);
$oh=imagesy($img);
$scale=$nw/$ow;
$nh=ceil($oh*$scale);
$newimg=imagecreate($nw,$nh);
imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh);
imagejpeg($newimg, $p.$nn);
return true;
}
#thumbnail(filetouse,newwidth,newpath,newname);
thumbnail("/img/x.jpg",100,"/img/thm/","xt.jpg");
?>