Click to See Complete Forum and Search --> : thumbs


killmunch
12-03-2003, 08:24 PM
i just need to know how to use this script i need a simple thumbnail script. dont really get php, so if you could explain this a little bit very greatful i would be

<?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");
?>

pyro
12-03-2003, 08:57 PM
Here it is, commented:

<?php
function thumbnail($i,$nw,$p,$nn) { # the function, with paramaters passed
$img=imagecreatefromjpeg("$i"); #Create a new image from file or URL
$ow=imagesx($img); #get the image's width
$oh=imagesy($img); #get the image's height
$scale=$nw/$ow; #divide $nw (passed to function) by image's width
$nh=ceil($oh*$scale); #multiply height by value returned above and round up.
$newimg=imagecreate($nw,$nh); #create a new image
imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh); #copy and resize the image
imagejpeg($newimg, $p.$nn); #output image
return true;
}

#thumbnail(filetouse,newwidth,newpath,newname);
thumbnail("/img/x.jpg",100,"/img/thm/","xt.jpg");
?>