Page 1 of 1

Automatic Image Resize

Posted: Sat Jan 03, 2004 4:35 pm
by naissa
Hey does any one know how to resize an image using php. I had a code before but it doesn't work in php 4

My code before

$image = $_GET['image'] ;
$newwidth = $_GET['newwidth'];
$newheight = $_GET['newheight'];
$height = $_GET['height'];
$width = $_GET['width'];
if (ereg('png$',$_GET[image])) { $src = imagecreatefrompng($image); }
if (ereg('jpg$',$_GET[image])) { $src = imagecreatefromjpeg($image); }
if (ereg('JPG$',$_GET[image])) { $src = imagecreatefromjpeg($image); }
if (ereg('gif$',$_GET[image])) { $src = imagecreatefromgif($image); }
$im = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($im,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagejpeg($im, '',85);
imagedestroy($im);

?>

Thanks

Posted: Sat Jan 03, 2004 5:59 pm
by JAM
I just added the correct header for the filetype, and it worked.

Code: Select all

header("Content-type: image/jpeg"); // Change to fit png and gif also...

Posted: Sat Jan 03, 2004 8:50 pm
by naissa
Is there another way to resize an image because the code above doesn't work for me in php 4?

Thanks

Posted: Sun Jan 04, 2004 5:38 am
by JAM
You can use Mogrify or other applications, but that depends on if they are installed, just as the above code needs GD to be installed to work.

Do a;

Code: Select all

<?php phpinfo(); ?>
...and see if you can see what version (if any) of GD is installed. Perhaps that might help some more.

image magick

Posted: Sun Jan 04, 2004 2:51 pm
by naissa
is there a way using image magick?

Posted: Sun Jan 04, 2004 3:11 pm
by JAM