Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using dynamic image generation

0 views
Skip to first unread message

Cat 22

unread,
Jan 2, 2010, 7:58:44 PM1/2/10
to
I have a php script that generates an image to stdout, i can redirect the
script to a file and load the file and thats ok, but what iwant to do is
something like this

<html>
<body>
<h1>It sorta works!</h1>
<img src="<?php tach.php?p=30 ?>" width=200 height=200 alt="tach">
</body>
</html>

The trouble is get only the image placeholder and the alt text but
no image.
tach.php has a content header and looks like this (some code dropped to
just show relevant stuff, I already am sure its creating an image)

<?php
header("Content-type: image/png");
$img=imagecreate(200,200);
[snip other stuff that makes the image]
imagepng($img);
imagedestroy($img);
?>
I'm using lighttpd and testing this on my local machine, i have phpsysinfo
installed and lighttpd handles that ok, so I think php itself is fine
also, "php-fastcgi -f tach.php" doesnt show any errors
I'm doing all this in linux.
My goal is to run a script that uploads weather info to my website every 5
minutes or so and the page would dynamically create the images for the
various instruments each time its loaded (or reloaded).
Thanks
Cat22

Doug Miller

unread,
Jan 2, 2010, 10:25:55 PM1/2/10
to
In article <hhoq44$cb7$2...@news.eternal-september.org>, Cat 22 <ca...@invalid.org> wrote:
>I have a php script that generates an image to stdout, i can redirect the
>script to a file and load the file and thats ok, but what iwant to do is
>something like this
>
><html>
><body>
><h1>It sorta works!</h1>
><img src="<?php tach.php?p=30 ?>" width=200 height=200 alt="tach">

Lose the script tags <?php and ?>, thus:

<img src="tach.php?p=30" width=200 height=200 alt="tach">

It's unclear why you believed they were necessary, since what's inside them is
*not* PHP code. It's just a URL.

cwdjrxyz

unread,
Jan 2, 2010, 11:44:32 PM1/2/10
to

Although I have often used php to generate buttons and such, I usually
just download them to my computer as png images. Some are buttons
without text which are then easy to upload to my site to add text with
php as needed. If I understand you correctly, you need to generate and
display a new image often even while the same page is being displayed.
This is a bit different from what I have needed so far, so I suggest
that you post in comp.lang.php if you do not get an answer here that
helps within the next day or so.

Peter

unread,
Jan 3, 2010, 8:36:22 AM1/3/10
to
In article <hhoq44$cb7$2...@news.eternal-september.org>, ca...@invalid.org
says...
Sounds like you're going to need some kind of javascript to do that
dynamically. Php is server-side and only works when the page is
requested, but once loaded that's it.

--
Pete Ives
Remove All_stRESS before sending me an email

Lars Eighner

unread,
Jan 3, 2010, 9:13:10 AM1/3/10
to
In our last episode,
<hhoq44$cb7$2...@news.eternal-september.org>,
the lovely and talented Cat 22
broadcast on alt.html:

> I have a php script that generates an image to stdout, i can redirect the
> script to a file and load the file and thats ok, but what iwant to do is
> something like this

><html>
><body>
><h1>It sorta works!</h1>
><img src="<?php tach.php?p=30 ?>" width=200 height=200 alt="tach">
></body>
></html>

> The trouble is get only the image placeholder and the alt text but
> no image.
> tach.php has a content header and looks like this (some code dropped to
> just show relevant stuff, I already am sure its creating an image)

The src attribute of IMG is not for the image itself, but for a link to the
image. This is just basic HTML. The image does not go in the HTML (yes,
there now are ways to get various kinds of binary data in HTML documents,
but that is not IMG with src.

Instead of <img src="<?php tach.php?p=30 ?>", <img src="tach.php?p=30"
should put you on the right track. Otherwise, whatever tach.php puts out
is what the browser will try to request. Obviously there is no such file.

A similar thing will happen if you try to include a static image binary
between the quotes of src. If it won't work with a static image, it sure
won't work with an image generated on the fly.

><?php
> header("Content-type: image/png");
> $img=imagecreate(200,200);
> [snip other stuff that makes the image]
> imagepng($img);
> imagedestroy($img);
> ?>
> I'm using lighttpd and testing this on my local machine, i have phpsysinfo
> installed and lighttpd handles that ok, so I think php itself is fine
> also, "php-fastcgi -f tach.php" doesnt show any errors
> I'm doing all this in linux.
> My goal is to run a script that uploads weather info to my website every 5
> minutes or so and the page would dynamically create the images for the
> various instruments each time its loaded (or reloaded).

How would you handle it if you did not want a previously cached static image
reloaded? You see that is a different problem than generating an image on
the fly. Be sure you are not confusing the two problems.

--
Lars Eighner <http://larseighner.com/> Warbama's Afghaninam day: 32
780.7 hours since Warbama declared Viet Nam II.
Warbama: An LBJ for the Twenty-First century. No hope. No change.

Jan C. Faerber

unread,
Jan 3, 2010, 12:09:25 PM1/3/10
to
On Jan 3, 1:58 am, Cat 22 <ca...@invalid.org> wrote:

> tach.php has a content header and looks like this (some code dropped to
> just show relevant stuff, I already am sure its creating an image)
>
> <?php
> header("Content-type: image/png");
> $img=imagecreate(200,200);
> [snip other stuff that makes the image]
> imagepng($img);
> imagedestroy($img);
> ?>

unfortunatly I don't know too much about it.
on linux webspaces it may be possible to use imagemagick - but on
windows servers not.
Well, this answer might only touch your backend problem - and not your
php issue.

Doug Miller

unread,
Jan 3, 2010, 1:56:20 PM1/3/10
to
[...]

>> My goal is to run a script that uploads weather info to my website every 5
>> minutes or so and the page would dynamically create the images for the
>> various instruments each time its loaded (or reloaded).
>>
>Sounds like you're going to need some kind of javascript to do that
>dynamically. Php is server-side and only works when the page is
>requested, but once loaded that's it.
>
A meta refresh tag will take care of reloading the page easily enough...

Doug Miller

unread,
Jan 3, 2010, 1:58:09 PM1/3/10
to
In article <090fc1dc-7c7b-4d62...@s3g2000yqs.googlegroups.com>, "Jan C. Faerber" <faerb...@gmail.com> wrote:

>On Jan 3, 1:58=A0am, Cat 22 <ca...@invalid.org> wrote:
>
>> tach.php has a content header and looks like this (some code dropped to
>> just show relevant stuff, I already am sure its creating an image)
>>
>> <?php
>> header("Content-type: image/png");
>> $img=3Dimagecreate(200,200);

>> [snip other stuff that makes the image]
>> imagepng($img);
>> imagedestroy($img);
>> ?>
>
>unfortunatly I don't know too much about it.
>on linux webspaces it may be possible to use imagemagick - but on
>windows servers not.
>Well, this answer might only touch your backend problem - and not your
>php issue.

*What* "php issue" are you talking about? He doesn't have a PHP issue. The
image won't display because his HTML is incorrect.

Cat 22

unread,
Jan 3, 2010, 2:41:49 PM1/3/10
to
Doug Miller wrote:

tach.php outputs the binary data bytes of the png image, not a filename, i
guess that isnt going to work?

Lars Eighner

unread,
Jan 3, 2010, 4:12:03 PM1/3/10
to
In our last episode, <hhqrtt$s6o$1...@news.eternal-september.org>, the lovely

and talented Cat 22 broadcast on alt.html:

> Doug Miller wrote:

tach.php is the url (aka filename); when the browser requests it, the
browser will get the image.

> i guess that isnt going to work?

It should work without the <?php tags. The server has to know to handle
tach.php as php, which it should if you are using php at all.

--
Lars Eighner <http://larseighner.com/> Warbama's Afghaninam day: 32

787.8 hours since Warbama declared Viet Nam II.

Doug Miller

unread,
Jan 3, 2010, 4:34:14 PM1/3/10
to

Did you try it????

0 new messages