image resizing and saving

From: Date: Fri, 04 Apr 2003 22:57:04 +0000
Subject: image resizing and saving
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-26842@lists.php.net to get a copy of this message
heyas i have the following code to resize an image to any wanted size: <? //$image2 = "image.jpg"; function resizeThatPic($image2){ $maxheight = 100; $maxwidth = 100; $size = getimagesize ("$image2"); $ratio = ($maxheight/$size[1]); $constrain_width = ($ratio * $size[0]); $constrain_height = ($ratio * $size[1]); if ($constrain_width > $maxwidth){ $mess = ($maxwidth/$size[0]); $constrain_width = ($ratio * $size[0]); $constrain_height = ($ratio * $size[1]); } $image = imagecreate($constrain_width,$constrain_height); $colorblue = imagecolorallocate($image, 0, 0, 255); imagefill($image, 0,0, $colorblue); if(!($image2 = @imagecreatefromjpeg("$image2"))){ $image = imagecreate($constrain_width,$constrain_height); $colorwhite = imagecolorallocate($image, 255, 255, 255); $colorblack = imagecolorallocate($image, 0, 0, 0); imagefill($image, 0, 0, $colorwhite); imagestring($image, 4, 10, 10, "Couldn't load image!", $colorblack); header("Content-type: image/jpeg"); imagejpeg($image); exit(); } imagecopyresized($image, $image2 , 0, 0, 0, 0, $constrain_width, $constrain_height, imagesx($image2), imagesy($image2)); header ("Content-type: image/jpeg"); imagejpeg($image); } ?> question 1: I want to use this in an other page: <? require ("imagetest.php"); resizeThatPic("image.jpg"); resizeThatPic("image2.jpg"); ?> The problem is that this only shows a resized image.jpg and no image2.jpg at all, why is that? and what can i do about it? question 2: Is there a way to save the resized image to another directory on the server? Thanks in advance :) Fedde

« previous php.db (#26842) next »