Re: Drawing Images Without Writing To a File

Re: Drawing Images Without Writing To a File

am 11.03.2010 16:25:59 von Ashley Sheridan

--=-enc8SrakH4PiNZwrUKYf
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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



--=-enc8SrakH4PiNZwrUKYf--

Drawing Images Without Writing To a File

am 11.03.2010 16:27:42 von 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

Re: Drawing Images Without Writing To a File

am 11.03.2010 16:40:53 von Kenneth 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.


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: Drawing Images Without Writing To a File

am 11.03.2010 16:43:40 von 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 src=3D'http://yourserver.com/project/imageScript.php?p1=3Da& p2=3Db">..

but ehm, image creation is bound to be a resource-intensive job..
you may want to cache the images.

On Thu, Mar 11, 2010 at 4:27 PM, Floyd Resler wrote=
:
> I want to draw tabs in a tab bar without having to actually write the ima=
ges to a file. =A0Is it possible to generate the image and send the data ba=
ck and make the browser think it's loading an image file? =A0I know this ca=
n 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
>
>

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

RE: Drawing Images Without Writing To a File

am 11.03.2010 16:52:33 von 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:ash@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: Drawing Images Without Writing To a File

am 11.03.2010 18:09:41 von 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
>=20
> I do something similar with my googled webcam :) Then you just use the =
script as the source for your image (i.e. src=3D"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.
>=20
> >=20
> header("Content-type: image/jpeg");
> $file =3D $_GET[src]; //"img/south-lawn1.jpg";
> $imgfile =3D "img/" . $file;
> $fsize =3D filesize($file);
> $string =3D "South Lawn @ " . date("Y-m-d H:i:s", filemtime($file));
>=20
> $im =3D imagecreatefromjpeg($file);
> $color =3D imagecolorallocate($im, 240, 240, 0);
> $px =3D (imagesx($im) - 9.5 * strlen($string));
> $py =3D (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);
>=20
> imagejpeg($im);
> imagedestroy($im);
>=20
> ?>
>=20
> ===3D
>=20
> 73,
> Ken Sande/KC8QNI-T


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