Ok, so I have tried everything I can think of and wandered the web too.. nothing seems to work.

I am trying to create an image with PHP. Which should work, but doesn't

<html>
<head></head>
<body><?php

header("Content-type: image/png");
$string = "image";
$im    = imagecreatefrompng("button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px    = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);

?></body></html>

the error is:

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\createImg\createImg.php:3) in C:\Program Files\Apache Group\Apache2\htdocs\createImg\createImg.php on line 5

have tried removing extra returns and white space in the code, in the ini files.... It's an Apapche 2 server with php 5.1.4

Please help me!!!!

Thanks in advance

    You don't need the HTML stuff it is a PHP file so rewrite and resave as

    <?php
    header("Content-type: image/png");
    $string = "image";
    $im    = imagecreatefrompng("button1.png");
    $orange = imagecolorallocate($im, 220, 210, 60);
    $px    = (imagesx($im) - 7.5 * strlen($string)) / 2;
    imagestring($im, 3, $px, 9, $string, $orange);
    imagepng($im);
    imagedestroy($im);
    ?>

      Basically, you can't output stuff on the page and then afterwards modify the header...Since the http header was already sent and hence can't be modified. (Amazing that the error messages acutally sometimes make sense!)

        yes, headers should be placed before getting any output by browser.

          And as Houdini observed, this script is generating a PNG image, so there shouldn't be any HTML anyway.

            Write a Reply...