php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15549 only incomplet output
Submitted: 2002-02-14 05:12 UTC Modified: 2002-02-15 13:07 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: michael at famberg dot net Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.0.6 OS: Windows XP with apache
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael at famberg dot net
New email:
PHP Version: OS:

 

 [2002-02-14 05:12 UTC] michael at famberg dot net
I have written a script which sample a resized image and create a copyrightstring on it. Then it should output the result on display. In most of times its makes wonderfull, but sometimes its output incomplet or empty images. Its happends every 10 times of try to load an image.
Here is the complete script:

function display_resized_image( $image, $newimage_extension, $newimage_height,$newimage_width,$quality=80,$tmpimagetype="image/jpeg")
{
	$image_size=getimagesize($image);
	$image_width=$image_size[0];
	$image_height=$image_size[1];
	
	//### get image
	$pathexploted=pathinfo($image);
	$image_extension=$pathexploted["extension"];
	if ($image_extension=="jpg" || $image_extension=="png" || $image_extension=="tmp")
	{
		
		if ($image_extension=="jpg")
		{
			$image_extension="jpeg";
		}
		if ($image_extension=="tmp")
		{
			$tmptype=explode("/",$tmpimagetype);
			if ($tmptype[0]=="image")
			{
				switch($tmptype[1])
				{
					case "jpeg":
						$image_extension="jpeg";
						break;
					case "jpg":
						$image_extension="jpeg";
						break;
					case "png":
						$image_extension="png";
						break;
				}
			}
			else
			{
				return -11;
			}
		}	
		$function="imagecreatefrom" . $image_extension;
		$image = $function($image);
	}
	else
	{
		return -12;
	}
	//### calculate new size
	if ($newimage_height==-1 && $newimage_width==-1)
	{
		$newimage_height=$image_height;
		$newimage_width=$image_width;
	}
	else
	{
		if ($newimage_width==-1)
		{
			$newimage_width=($image_width*$newimage_height)/$image_height;
		}
		if ($newimage_height==-1)
		{
			$newimage_height=($image_height*$newimage_width)/$image_width;
		}
	}	
	
	//### create buffer image and sample resized image
	$buffer = imagecreatetruecolor($newimage_width,$newimage_height);
	imagecopyresampled($buffer,$image,0,0,0,0,$newimage_width ,$newimage_height,$image_width,$image_height);
	
	if ($newimage_width>=250)
	{
		//### Copyrightbild erstellen
		$cpbuffer = imagecreatetruecolor(300,30);
		imagestring ($cpbuffer, 5, 45, 8, "(C)2002 www.shopforkids.de", imagecolorexact($cpbuffer, 255, 255, 255));
		
		//### alising line
		$linebuffer = imagecreatetruecolor(300,2);
		//### Copyrightbild einblenden
		imagecopymerge($buffer,$cpbuffer,$newimage_width-300,$newimage_height-30,0,0,300,30,40);
		imagecopymerge($buffer,$linebuffer,$newimage_width-300,$newimage_height-32,0,0,300,2,20);
	}
		
	//### shows images
	if ($newimage_extension=="jpg" || $newimage_extension=="png" || $newimage_extension=="jpeg")
	{
		if ($newimage_extension=="jpg")
		{
			$newimage_extension="jpeg";
		}
		Header("Content-type: image/" . $newimage_extension);
		$function="image" . $newimage_extension;
		//$function="imagepng";
		if ($function=="imagejpeg")
		{
			$function($buffer,"",$quality);
		}
		else
		{
			$function($buffer);
		}
	}
	else
	{
		return -21;
	}
imagedestroy($buffer);
imagedestroy($cpbuffer);
imagedestroy($linebuffer);
}
Im sorry for my bad english.
Michael Berg

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-14 05:25 UTC] michael at famberg dot net
The gd version is 2.0 or higher(phpinfo);
and the php version is 4.0.6
 [2002-02-15 13:07 UTC] sander@php.net
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit http://www.php.net/support.php

GD is not thread safe (at least, not on Windows).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 05:01:31 2024 UTC