imagecopyresampled looks awful

From: Date: Wed, 21 May 2003 23:21:27 +0000
Subject: imagecopyresampled looks awful
Groups: php.general 
Request: Send a blank email to php-general+get-148468@lists.php.net to get a copy of this message
I want to allow a user to enter an image into a CMS and not worry about image size. I used imagecopyresampled to resize the jpeg when saving. The resizing from a larger to smaller results in an image that is awful. The color is ruined and the picture is pixelated (if that's a word). Here's the code if you're interested, but how do resize and maintain an from a larger to smaller imagesize and maintain an acceptable image. ------------------ <? include("../admin/constant.php"); $location = $_GET['location']; $filename = $_GET['filename']; $max_width = $_GET['width']; $max_height = $_GET['height']; $image = IMAGEDIR . "/" . $location . "/" . $filename; $im = ImageCreateFromJPEG($image); $FullImage_width = imagesx ($im); // Original image width $FullImage_height = imagesy ($im); $ratio = ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ; $new_width = ((int)($FullImage_width * $ratio)); //full-size width $new_height = ((int)($FullImage_height * $ratio)); //full-size height $ratio = ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ; $new_width = ((int)($new_width * $ratio)); //mid-size width $new_height = ((int)($new_height * $ratio)); //mid-size height $rimage = imagecreate($max_width, $max_height); imagecopyresampled($rimage, $im, 0, 0, 0, 0, $new_width, $new_height, $FullImage_width, $FullImage_height); header("Content-type: image/jpeg"); imagejpeg($rimage); imagedestroy($rimage); imagedestroy($image); ?> __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com

« previous php.general (#148468) next »