Jump to content


Photo

JPEG headers


  • Please log in to reply
1 reply to this topic

#1 dig412

dig412
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 February 2006 - 09:36 PM

I'm using this code to make a simple speech bubble generator, and so far its working fine. However, if you choose 'save image' in firefox, it will save the blank image without the added text. It saves properly in ie, so i dont know exactly whats wrong.

if (isset($_GET['mode'])){
if ($_GET['mode'] == "img") {
 header ("Content-type: image/jpeg");
 header('Content-transfer-encoding: binary');
 putenv('GDFONTPATH=' . realpath('.'));
 $image = $_POST['image'];
 if ($image == "shout") {
 $img_handle = @ImageCreateFromJPEG ("domotalk.jpg");
 }
 else{
 $img_handle = @ImageCreateFromJPEG ("domonews.jpg");
 }
 $txt_color = ImageColorAllocate ($img_handle, 0, 0, 0);
 $text = $_POST['usertxt'];
 if ($image == "shout") {
 $newtext = wordwrap($text, 17, "\n", 1);
 }
 else {
 $newtext = wordwrap($text, 20, "\n", 1);
 }
 $font = 'arial';
 if ($image == "shout") {
 ImageTTFText ($img_handle, 14, 0, 207, 62, $txt_color, $font,"$newtext");
 }
 else {
 ImageTTFText ($img_handle, 14, 0, 280, 75, $txt_color, $font,"$newtext");
 }
 ImageJPEG ($img_handle,'',95);
 }
 }

I'm assuming that it's got something to do with the headers.
Any ideas?

EDIT:
It seems it doesn;t work with IE anymore. hmm

#2 RussellReal

RussellReal
  • Members
  • PipPipPip
  • Advanced Member
  • 1,774 posts
  • LocationTobyhanna, Pennsylvania

Posted 30 December 2008 - 12:34 PM

<?
	if (isset($_GET['mode'])){
		if ($_GET['mode'] == "img") {
			header ("Content-type: image/jpeg");
			header('Content-transfer-encoding: binary');
			putenv('GDFONTPATH=' . realpath('.'));
			$image = $_POST['image'];
			$text = $_POST['usertxt'];
			$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
			$font = 'arial';
			$img_handle = @ImageCreateFromJPEG((($image == "shout")? "domotalk":"domonews").".jpg");
			if ($image == "shout") {
				$newtext = wordwrap($text, 17, "\n", 1);
				ImageTTFText($img_handle, 14, 0, 207, 62, $txt_color, $font, $newtext);
			}
			else{
				$newtext = wordwrap($text, 20, "\n", 1);
				ImageTTFText($img_handle, 14, 0, 280, 75, $txt_color, $font, $newtext);
			}
			ImageJPEG ($img_handle,NULL,95);
		}
	} 
?>

only problem I can see is $font is being set to 'arial' and 'arial' is not a font file.. the font parameter for imagettftext is a FONT FILENAME

yes I know this post is over 2 yrs old.. whatever.. I'm bored
Like my help and want to hire me? Email me or add me to MSN at RussellonMSN@hotmail.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users