Displaying a fresh generated image.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Displaying a fresh generated image.

Post by fastfingertips »

I have generated a new image, how can i display it into other file where i have also other texts?

My function looks:

Code: Select all

<?php
header("Content-type: image/png");
    function WriteImage($string)
    {    
        $im     = imagecreatefrompng("bgimage.png");
        $orange = imagecolorallocate($im, 220, 210, 60);        
        imagestring($im, 5, 10, 4, $string, $orange);        
        
        imagepng($im);
        imagedestroy($im);
    }
?>
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Put your image code into a seperate PHP file and include it in HTML with something like <img src="image.php?string=hello" alt="" />

image.php would look like this...

Code: Select all

<?php ob_start();

$string = $_GET["string"];
  
$im = imagecreatefrompng("bgimage.png");
$orange = imagecolorallocate($im, 220, 210, 60);       
imagestring($im, 5, 10, 4, $string, $orange);       

header("Content-type: image/png");       
imagepng($im);
imagedestroy($im);

ob_end_flush(); ?>
Post Reply