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

2010-03-11 Thread Floyd Resler
Ken,
That's exactly what I want and it works beautifully!  I wish I had 
asked this question a long time ago since, in the past, I have been creating 
the files and wind up with a bunch of image files hanging around.  When 
building this new site I thought there must be a better way!

Thanks!
Floyd

On Mar 11, 2010, at 10:40 AM, Ken Sande wrote:

> 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.
> 
>  
> 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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2010-03-11 Thread David Murphy
Also you should think about  writing those files  a memcache or something.

That way   the image can expire but you're not wasting a lot of cpu cycles,
aka   500 hits to the site at the same time would be  very  intensive, but
if someone hit the site 10 minutes ago with a  700 ttl,  the would load the
image instantly from ram ;)

Also a method I like is 


class thumbnail  {

 function __construct($baseFileName){
 if (!file_exists(THUMBS."/".$baseFileName)
 $this->generateThumbnail($baseFileName);
 return $this->outputThumbContents($baseFileName);
 }
 function outputThumbContents($sFileName){
 //Reads file and echo its  header/contents
 }
}

Which of course you could make  check a  memcache location instead or
memcache,file,then build if neither is present. :)

David 

-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Thursday, March 11, 2010 9:26 AM
To: Floyd Resler
Cc: PHP
Subject: Re: [PHP] Drawing Images Without Writing To a File

On Thu, 2010-03-11 at 10:27 -0500, 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
> 
> 


Have the image tag call a script which generates the images based on
parameters in the filename:



Then you can have PHP read in the GET data and generate any image you
need.

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2010-03-11 Thread Rene Veerman
sure..

have a seperate php script output the image you want (after doing a
header() call to set the mime type to an image; google "php header
image"), and call that on the relevant page via  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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2010-03-11 Thread Ken Sande

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.


imagestring($im, 5, 10, $py - 16, round(( $fsize / 1024 ),1) . "kB", 
$color);


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

?>

===

73,
Ken Sande/KC8QNI-T

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2010-03-11 Thread Ashley Sheridan
On Thu, 2010-03-11 at 10:27 -0500, 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
> 
> 


Have the image tag call a script which generates the images based on
parameters in the filename:



Then you can have PHP read in the GET data and generate any image you
need.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Drawing Images Without Writing To a File

2010-03-11 Thread Floyd Resler
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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php