Jump to content

PHP image and html won't print on same page


deathraylabs

Recommended Posts

O.K., it is a graph that someone else created. Hope this helps. Any example would work as long as it put an image and html on the same page. Have been trying to figure this out for days. - Thanks


[code]<?
    function createGraph($graphValues)
    {
    global $image;

    $imgWidth=250;
    $imgHeight=250;

    // Create image and define colors
    $image=imagecreate($imgWidth, $imgHeight);
    $colorWhite=imagecolorallocate($image, 255, 255, 55);
    $colorGrey=imagecolorallocate($image, 192, 192, 192);
    $colorBlue=imagecolorallocate($image, 0, 0, 255);
    $colorLightBlue=imagecolorallocate($image, 167, 211, 237);
    $colorDarkBlue=imagecolorallocate($image, 5, 107, 165);

    // Create border around image
    imageline($image, 0, 0, 0, 250, $colorGrey);
    imageline($image, 0, 0, 250, 0, $colorGrey);
    imageline($image, 249, 0, 249, 249, $colorGrey);
    imageline($image, 0, 249, 249, 249, $colorGrey);

        // Create grid
        for ($i=1; $i<11; $i++){
        imageline($image, $i*25, 0, $i*25, 250, $colorGrey);
        imageline($image, 0, $i*25, 250, $i*25, $colorGrey);
        }

        // Create bar charts


        for ($i=0; $i<10; $i++){
        imagefilledrectangle($image, $i*25, (250-$graphValues[$i]), ($i+1)*25, 250, $colorDarkBlue);
        imagefilledrectangle($image, ($i*25)+1, (250-$graphValues[$i])+1, (($i+1)*25)-5, 248, $colorLightBlue);
        }

    return($image);
    }


//    echo 'if this line is included after the image, my image shows but not this text. If I place this text before the image/header info, I don\'t get either.';

    $graphValues=array(20,80,23,11,200,245,50,80,111,15,55);
    createGraph($graphValues);

    header('Content-type: image/png');
    header('Content-Length: ' . strlen($image));

    echo '<img src="' . imagePNG($image) . '" width="250" height="250">';


//    echo 'if this line is included after the image, my image shows but not this. If I place this before the image/header info, I don\'t get either.';
?>[/code]
it's because you are sending headers and then trying to display html. divide the 2 into 2 different scripts and have your html script call the image like normal, but with the image script as the source:

[code]
<img src='image.php' />
[/code]

if you are having trouble with seperating the 2, look into captcha tutorials; it's essentially the same thing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.