Automatic Image Resize

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naissa
Forum Newbie
Posts: 4
Joined: Sat Jan 03, 2004 4:35 pm

Automatic Image Resize

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
naissa
Forum Newbie
Posts: 4
Joined: Sat Jan 03, 2004 4:35 pm

Post by naissa »

Is there another way to resize an image because the code above doesn't work for me in php 4?

Thanks
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
naissa
Forum Newbie
Posts: 4
Joined: Sat Jan 03, 2004 4:35 pm

image magick

Post by naissa »

is there a way using image magick?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Post Reply