Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Premature End of Script Headers on GD call 1

Status
Not open for further replies.

kasuals

Programmer
Apr 28, 2002
100
US
Here is a snippet I modified. Basically it's to set transparent text over a background:



Code:
<?
	header('Content-type: image/jpeg'); 
	$im = ImageCreateFromJpeg(&quot;bg.jpg&quot;);
	$im_w = imagesx($im); // Get the image width 
	$im_h = imagesy($im); // Get the image height 
	$col = imagecolorallocate($im, 0, 0, 0);
	imagesetpixel($im,$im_w-1,0,$col); 
	$new = imagecreate($im_w,$im_h); // Create a buffer 
	$index = imagecolorat($im,$im_w-1,0); // Get the color at that pixel 
	$rgb = imagecolorsforindex($im,$index); // Get the index of that color 
	$r = $rgb[&quot;red&quot;]; // Get the red value 
	$g = $rgb[&quot;green&quot;]; // Get the green value 
	$b = $rgb[&quot;blue&quot;]; // Get the blue value 
	$color = imagecolorallocate($new,$r,$g,$b); // Allocate this color on the buffer 
	$copy = imagecopy($new,$im,0,0,0,0,$im_w,$im_h); // Copy the old image onto the buffer 
	$text = imagettftext($new,20,0,10,10,$color,&quot;c:\windows\fonts\arial.ttf&quot;,&quot;test&quot;); // Draw the text 
	$merge = imagecopymerge($im,$new,0,0,0,0,$im_w,$im_h,50); // Copy the buffer back onto the original image 
	imagedestroy($new); // Destroy the buffer 
	imagejpeg($im);
?>

I get a premature end of script headers when I don't comment out the imagecopy(). Any ideas? I'm new to the GD library... in fact I have yet to find a decent tutorial online that actually EXPLAINS what everything does... anyone have any good tutorials as well?

- &quot;Delightfully confusing...&quot; raves The New York Times

-kas
 
There is a known bug or quirk of the GD library that you can't copy two types of images onto one another. Apparently, imagecreatefromjpeg() creates a TrueColor image, but imagecreate() creates a palette image.

Try changing this line:

$new = imagecreate($im_w,$im_h); // Create a buffer

To read:

$new = imagecreatetruecolor($im_w,$im_h); // Create a buffer


Want the best answers? Ask the best questions: TANSTAAFL!!
 
You, as always are the MAN sleip. The amount of knowledge in the realm of PHP you possess continues to amaze me.

Thank you again for your help.

- &quot;Delightfully confusing...&quot; raves The New York Times

-kas
 
sleip, I had a quick question (although the answer may not be so quick).

The tutorials and whatnot I have looked at don't explain anything, they just say &quot;do it like this&quot;... I want to know why this works for transparency?

What makes the text transparent? Is it the copymerge that sets the opacity on the ttf buffer?

- &quot;Delightfully confusing...&quot; raves The New York Times

-kas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top