[thelist] PHP image resize

ben morrison ben at benjer.demon.co.uk
Wed Sep 1 07:01:46 CDT 2004

Im just learning PHP so this may be really obvious, I have built a  
simple file upload and am now trying to create a thumbnail on the fly  
which is scaled proportionally.

On my server PHP 4.1.2 GD 1.6 Globals are set to ON.

constantly getting parse errors, this is my current code:

$first=ImageCreateFromJPEG("images/".$_FILES['MyFile']['name']) or  
die("couldn't open image");
define(MAX_WIDTH, 150);
define(MAX_HEIGHT, 150);
$width = imagesx($first);
$height = imagesy($first);

$scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);

$new_width = floor($scale*$width);
$new_height = floor($scale*$height);

$second=ImageCreate($new_width, $new_height) or die("couldn't create  

eight) or die("coudln't resize image");

ImageJPEG($second,$thumbname) or die("couldn't save image");

the original image is working, $thumbname exists, ive just shown the  
code thats causing the error.

Ive tried so many different codes from tutorial sites and most of them  
don't seem to work - I presume this is due to versions and globals etc?


More information about the thelist mailing list