Bug #18460: Gd Hangs when Resampling and saving PNG's
| From: | sramage at fatpipeinternet dot com | Date: | Sun, 21 Jul 2002 17:41:03 +0000 |
| Subject: | Bug #18460: Gd Hangs when Resampling and saving PNG's | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-14743@lists.php.net to get a copy of this message | ||
From: sramage@fatpipeinternet.com
Operating system: FreeBSD
PHP version: 4.2.1
PHP Bug Type: GD related
Bug description: Gd Hangs when Resampling and saving PNG's
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 bug report at http://bugs.php.net/?id=18460&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18460&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18460&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18460&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18460&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18460&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18460&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18460&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18460&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18460&r=globals