Forum Moderators: coopster

Message Too Old, No Replies

JPEG Image with text Just not workin!

Jpeg and more

         

HeadBut

3:35 pm on Oct 24, 2004 (gmt 0)

10+ Year Member



can someone look at this and point me in the right direction, never done this GD library stuff:
<?php

header("Content-type: image/jpg");

$TableNumber=$_GET['TableNumber'];
$imjpg = imagecreatefromjpeg("/images/rmsnotext.jpg");
$TableNumber_color = ImageColorAllocate ($imjpg, 213, 43, 43);
$px = (imagesx($imjpg)-7.5*strlen($TableNumber))/2;
ImageString($imjpg,3,$px,9,$TableNumber,$TableNumber_color);
ImageJpeg($imjpg);
ImageDestroy($imjpg);

?>

This code is not working, do I really need the "ImageDestroy($imjpg);"
And I'm not really sure how to position the text.... maybe a better tutorial someplace?

Many Thanks

mincklerstraat

3:59 pm on Oct 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It'd probably help here if you let us know what wasn't working for you with this code - is it just the positioning?

I've never tried fancy text positioning when using image_string - if you're prepared to use truetype fonts instead (which is a few rungs up the ladder of coolness to boot), you can also get a pretty precise idea of how much space in pixels your text is going to take before you go printing it out with imagettfbbox [be2.php.net].
I've used this to get my image text centered, real sweet. You'll then be using

imagettftext()
to print out your text.

I think imagedestroy() is a good idea - there have been nightmare stories reported of people who didn't use it once their sites went into production and got big traffic.

HeadBut

2:33 am on Oct 25, 2004 (gmt 0)

10+ Year Member



I'm not getting an image from this script. How can I debug this?

mincklerstraat

8:13 am on Oct 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




function log_image_error($array){
error_log(print_r(func_get_args($array), TRUE), 3, 'imageerror.txt');
}
set_error_handler('log_image_error');

You can try this to help you debug. Paste this at the top of your code (remove parse errors if any), and create a file in the same directory named imageerror.txt, set to be writeable by the server. Run your script and then look in this file to see if there are errors reported. You can see what the values mean on the page set_error_handler.

Another thing: when it won't produce an image, comment out temporarily the 'header' line so the error messages will come out as plain text (in fact, do this first, before pasting the above etc.).

I'm guessing on imagestring, you're somehow going over the boundaries. Try this with x and y parameters 0 and see if it works.