Re: Resizing Pictures

From: Date: Tue, 20 Apr 2004 05:47:35 +0000
Subject: Re: Resizing Pictures
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-183921@lists.php.net to get a copy of this message
This will resize JPG images: function get_image_width($image) { $imgsize = getimagesize($image); return $imgsize[0]; } function get_image_height($image) { $imgsize = getimagesize($image); return $imgsize[1]; } function resize_image($originalimage, $dest_width, $save_path, $newfilename) { $file_ext = strstr($newfilename, '.'); $width = get_image_width($save_path.$originalimage); $height = get_image_height($save_path.$originalimage); // If the width is bigger than the destination width, reduce the image size. if ($width > $dest_width) { $aspectratio = ($width-$dest_width)/$width; $newwidth = ceil($dest_width); $newheight = ceil($height-($height*$aspectratio)); if (strtoupper($file_ext) == ".JPG") if (function_exists("imagejpeg")) { $src_img = imagecreatefromjpeg($save_path.$originalimage); if (imageistruecolor($src_img)) $dst_img = imagecreatetruecolor($newwidth, $newheight); else { echo $originalimage." is not a true color image."; exit(); } imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($dst_img, $save_path.$newfilename, 80); imagedestroy($src_img); imagedestroy($dst_img); } } // Must be the same width or less, just save it. else if (!copy($save_path.$originalimage, $save_path.$newfilename)) { echo "unable to copy file"; exit(); } return $newfilename; } "Ryan Schefke" <ryanschefke@triomfgroup.com> wrote in message news:auto-000650834511@front3.chartermi.net... > > > How do you resize pictures once they're in a certain directory? I have the > script to upload a picture, that's working fine. I just need some help with > resizing it. Can someone help? > > > > Thanks! > >

« previous php.general (#183921) next »