using dynamic image generation

C

Cat 22

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
 
D

Doug Miller

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

cwdjrxyz

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

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

Peter

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

Lars Eighner

In our last episode,
<[email protected]>,
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.
 
J

Jan C. Faerber

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

Doug Miller

says... [...]
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...
 
D

Doug Miller

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

Cat 22

Doug said:
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.

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

Lars Eighner

the lovely said:
Doug Miller wrote:
tach.php outputs the binary data bytes of the png image, not a filename,

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top