php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18460 Gd Hangs when Resampling and saving PNG's
Submitted: 2002-07-21 13:41 UTC Modified: 2006-05-15 20:49 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: sramage at fatpipeinternet dot com Assigned:
Status: No Feedback Package: GD related
PHP Version: 4.2.1 OS: FreeBSD
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-07-21 13:41 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-22 21:18 UTC] 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-22 22:11 UTC] 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-23 15:26 UTC] 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-09-11 11:55 UTC] 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.


 [2006-05-15 20:14 UTC] blackjayde at xtremegaming dot net
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.
 [2006-05-15 20:49 UTC] pajoye@php.net
"blackjayde at xtremegaming dot net"

Without a small script and some sample PNG files, I have no way to know what's going wrong.

Also using 4.3.11 is not going to help either. Please try 4.4.2, 5.1.4, or the snapshot (snaps.php.net). I keep this bug to "no feedback" as nothing new has been brought.
 [2006-05-15 23:35 UTC] blackjayde at xtremegaming dot net
Issue resolved on my part.  Was a compile issue.  When using --with-png and --with-png-dir=/usr, it fails to work.  Just using the single switch --with-png-dir=/usr works.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 11:01:33 2024 UTC