Image Create

Havving trouble using image create. Here is the code


header(“Content-type: image/png”);
$im = imagecreate(100, 50)
or die(“Cannot Initialize new GD image stream”);
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, “A Simple Text String”, $text_color);


here is the browser output

?PNG IHDRd2????PLTE????[????eIDAT(?c` `fx???`? ???????? [vK???§? ? ??6p¦)??u.``iP o9??¦??©Ty?????????¬?X&Z?u [email protected]?m?IEND®B`?

Supposed to be GD version to or higher

php info can be viewed here

Anyone have any idea how to sort this

This code works fine for me. Make sure there is nothing before the header() stuff. This has to be the first line after <?php of course.

If you are positive that there is nothing before it, you may need to try a different editor. I have a problem when trying to use wordpad or something similar. Copy the code into notepad and try saving it again using that.

Some text editors put in hidden information that mess with php and header stuff.

I’m using dreamweaver mx

have just tried notepad and its returning the same error

Try, putting error_reporting(E_ALL) at the top and see if you get anything different.

getting this at top

Warning: Cannot modify header information - headers already sent by (output started at /data/members/paid/s/u/ in /data/members/paid/s/u/ on line 7

I think i’ve sorted it

removed the html head and body tags and it working ok now but why is that

thats output.

<html><?php header(...)is the same as

<?php echo "<html>"; header(...)

the http-protocol has a http-header at its beginning. and then it just puts out content. it cant put out content before tzhe header is not “closed”. so the header has to end if u use echo or text outside <?php ?>. that means php is not sending the header right from the beginning. php does so as soon as u output content. and then u cant go bach and modyfy the haeder thats allredy sent to the browser.

just remenber NO output before header() and session_start(), not even a linefeed or blank.

Sponsor our Newsletter | Privacy Policy | Terms of Service