Re: [PHP] Drawing Images Without Writing To a File

[email protected] (Ken Sande)
Newsgroups php.general
Message-ID <[email protected]>
Floyd Resler wrote:
> I want to draw tabs in a tab bar without having to actually write the images to a file.  Is it possible to generate the image and send the data back and make the browser think it's loading an image file?  I know this can be done by sending the proper headers back for an entire page, but I just want to do basically the same thing for just part of the page.
> 
> Thanks!
> Floyd
> 
> 

I do something similar with my googled webcam :) Then you just use the 
script as the source for your image (i.e. src="img.php?arguments"). 
Hopefully this is what you are looking for. (Note, this uses the 
processor pretty heavily when I run 100 images or so).
If you are going to reuse the images for many clients, it may be a 
better alternative to reuse the generated image.

<?php

header("Content-type: image/jpeg");
$file = $_GET[src];	//"img/south-lawn1.jpg";
$imgfile = "img/" . $file;
$fsize = filesize($file);
$string = "South Lawn @ " . date("Y-m-d H:i:s", filemtime($file));

$im     = imagecreatefromjpeg($file);
$color = imagecolorallocate($im, 240, 240, 0);
$px     = (imagesx($im) - 9.5 * strlen($string));
$py	= (imagesy($im) - 24);
imagestring($im, 5, $px, $py, $string, $color);
imagestring($im, 5, 10, $py, $file, $color);
imagestring($im, 5, 10, $py - 16, round(( $fsize / 1024 ),1) . "kB", 
$color);

  imagejpeg($im);
  imagedestroy($im);

?>

===

73,
Ken Sande/KC8QNI-T
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.