Bug #18460 Updated: Gd Hangs when Resampling and saving PNG's
| From: | sniper@php.net | Date: | Tue, 23 Jul 2002 19:26:18 +0000 |
| Subject: | Bug #18460 Updated: Gd Hangs when Resampling and saving PNG's | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-14935@lists.php.net to get a copy of this message | ||
ID: 18460
Updated by: sniper@php.net
Reported By: sramage@fatpipeinternet.com
-Status: Open
+Status: Feedback
Bug Type: GD related
Operating System: FreeBSD
PHP Version: 4.2.1
New Comment:
I can not reproduce this with latest CVS of PHP when using
libpng 1.2.0 and GD 2.0.1.
Previous Comments:
------------------------------------------------------------------------
[2002-07-22 22:11:08] sramage@fatpipeinternet.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@fatpipeinternet.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