PHP GD & Graphs - Help!

They have: 2 posts

Joined: Dec 2009

Hello im currently messing around with PHP GD and im trying to complete a simple tutorial.

My code:

<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5'A Simple Text String', $text_color);

// Set the content type header - in this case image/jpeg
header('Content-type: image/jpeg');

// Output the image
imagejpeg($im);

// Free up memory
imagedestroy($im);
?>

any ideas to why im getting garbled text output? ive even had this same file uploaded to another server which used the same tutorial and worked.

Thanks,

Gary

He has: 698 posts

Joined: Jul 2005

I would say you need to make sure that for some reason GD is not disabled on your server. Otherwise, you might try using the imagepng() function instead and see if it makes any difference. If it does make a difference, support for JPEG output must not be available with your version of PHP/GD; otherwise, I would say it's a problem with the server itself as this seems to be an exact copy of the sample script available at the PHP.net website. Sticking out tongue

Kurtis

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.