#18460 [Com]: Gd Hangs when Resampling and saving PNG's

From: Date: Mon, 15 May 2006 20:14:51 +0000
Subject: #18460 [Com]: Gd Hangs when Resampling and saving PNG's
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-97135@lists.php.net to get a copy of this message
ID: 18460 Comment by: blackjayde at xtremegaming dot net Reported By: sramage at fatpipeinternet dot com Status: No Feedback Bug Type: GD related Operating System: FreeBSD PHP Version: 4.2.1 New Comment: Having the same issue. PHP 4.3.11 Apache 1.3.29 libpng 1.2.1-2 libpng10 1.0.13-5 gd-1.8.4-7 JPEG, PNG enabled Seems to fail on anything related to png code (ImageCreateFromPNG, ImagePng, etc). Works perfect using Jpeg. Previous Comments: ------------------------------------------------------------------------ [2002-09-11 11:55:18] sniper@php.net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. ------------------------------------------------------------------------ [2002-07-23 15:26:18] sniper@php.net I can not reproduce this with latest CVS of PHP when using libpng 1.2.0 and GD 2.0.1. ------------------------------------------------------------------------ [2002-07-22 22:11:08] sramage at fatpipeinternet dot com //Sorry 'bout that, Brain Freeze =) function CreateThumbnail($input_image,$output_image){ $image = ImageCreateFromPNG($input_image); $thumb = ImageCreateTrueColor(75, 75); $bg = ImageColorAllocate($thumb, 255, 255, 255); ImageFill($thumb, 0, 0, $bg); ImageCopyResampled ($thumb, $image, 0, 0, 0, 0, 75,75, ImageSX($image), ImageSY($image)); return ImagePNG($thumb, "$output_image"); }//end function CreateThumbnail("original.png","thumb.png"); ------------------------------------------------------------------------ [2002-07-22 21:18:45] sniper@php.net Please provide a short, self-contained script which is as short as possible, preferrably under 10 lines of code. And such script which can be easily cut'n'pasted and run.. (without any need of huge rewrites) ------------------------------------------------------------------------ [2002-07-21 13:41:02] sramage at fatpipeinternet dot com This error occurs almost every time, once every 20 times it actually works but most times it hangs. Some times It actually finishes writing the file than it doesn't hang, it just autopmatically comes up with the standard -- Cannot find server or DNS Error -- there is no problem with the DNS it just gives that error when it actually completes the file write. if it does not complete the file write the file size of the created image == 0 and the browser goes into a constant loading cycle, but never loads the page. Stats Apache 1.3.22 GD Version 2.0 or higher JPEG, PNG enabled The following function is usually called within a class, if that matters. it's not a bad piece of thumbnail code, feel free to use it at will. Thanks Steve function CreateThumbnail($input_image,$fixed=true,$width=75,$height=75,$output_image=false){ //echo "$input_image<BR>$output_image <BR><BR>"; if(file_exists($input_image)){ // No Output File? Lets Improvise... if(!$output_image){ $ext=strrev(strtok(strrev($input_image),".")); $core=strrev(strtok("")); $output_image=$core."_thumb.".$ext; } // Snag Image Size if($dimensions = @GetImageSize($input_image)){ if($dimensions[2]==3 || $dimensions[2]==2){ // Set Height to Width Ratio. $ratio = $dimensions[1] / $dimensions[0]; // Set up Thumbnail Dimensions if($fixed){ $new_height = $height; $new_width = $width; $x = 0; $y = 0; }else{ if ($ratio * $width < $height) { // if Height is greater than Width $new_height = $ratio * $width; $new_width = $width; $x = 0; $y = ($height - $new_height) / 2; }else if ((1 / $ratio) * $height < $width) { // if Width is greater than Height $new_width = (1 / $ratio) * $height; $new_height = $height; $x = ($width - $new_width) / 2; $y = 0; }else { // if Width is equal to Height $new_width = $width; $new_height = $height; $x = 0; $y = 0; } } // Load up original image switch($dimensions[2]){ case '3': $image = ImageCreateFromPNG($input_image); break; case '2': $image = ImageCreateFromJPEG($input_image); break; default: $image=false; break; } if($image){ // Create thumbnail in memory $thumb = @ImageCreateTrueColor($width, $height); $bg = @ImageColorAllocate($thumb, 255, 255, 255); @ImageFill($thumb, 0, 0, $bg); // Paste a resized original within the thumb borders @ImageCopyResampled ($thumb, $image, $x, $y, 0, 0, $new_width, $new_height, @ImageSX($image), @ImageSY($image)); // Write Completed Thumbnail to Disk if($dimensions[2]==3){ $return=@ImagePNG($thumb, "$output_image"); }else{ $return=@ImageJpeg($thumb, "$output_image"); } } }else{ $return=false; //$this->error="cannot create thumbnail from specified image type"; } }else{ $return=false; } }else{ $return=false; } return $return; }//end function ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18460&edit=1

« previous php.bugs (#97135) next »