using dynamic image generation

Discussion in 'HTML' started by Cat 22, Jan 3, 2010.

  1. Cat 22

    Cat 22 Guest

    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
    Cat 22, Jan 3, 2010
    #1
    1. Advertising

  2. Cat 22

    Doug Miller Guest

    In article <hhoq44$cb7$-september.org>, Cat 22 <> 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.
    Doug Miller, Jan 3, 2010
    #2
    1. Advertising

  3. Cat 22

    cwdjrxyz Guest

    On Jan 2, 6:58 pm, Cat 22 <> 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">
    > </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.
    cwdjrxyz, Jan 3, 2010
    #3
  4. Cat 22

    Peter Guest

    In article <hhoq44$cb7$-september.org>,
    says...
    > 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.

    --
    Pete Ives
    Remove All_stRESS before sending me an email
    Peter, Jan 3, 2010
    #4
  5. Cat 22

    Lars Eighner Guest

    In our last episode,
    <hhoq44$cb7$-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.
    Lars Eighner, Jan 3, 2010
    #5
  6. On Jan 3, 1:58 am, Cat 22 <> 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.
    Jan C. Faerber, Jan 3, 2010
    #6
  7. Cat 22

    Doug Miller Guest

    In article <>, Peter <> wrote:
    >In article <hhoq44$cb7$-september.org>,
    >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...
    Doug Miller, Jan 3, 2010
    #7
  8. Cat 22

    Doug Miller Guest

    In article <>, "Jan C. Faerber" <> wrote:
    >On Jan 3, 1:58=A0am, Cat 22 <> 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.
    Doug Miller, Jan 3, 2010
    #8
  9. Cat 22

    Cat 22 Guest

    Doug Miller wrote:

    > In article <hhoq44$cb7$-september.org>, Cat 22
    > <> 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.


    tach.php outputs the binary data bytes of the png image, not a filename, i
    guess that isnt going to work?
    Cat 22, Jan 3, 2010
    #9
  10. Cat 22

    Lars Eighner Guest

    In our last episode, <hhqrtt$s6o$-september.org>, the lovely
    and talented Cat 22 broadcast on alt.html:

    > Doug Miller wrote:


    >> In article <hhoq44$cb7$-september.org>, Cat 22
    >> <> 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.


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

    --
    Lars Eighner <http://larseighner.com/> Warbama's Afghaninam day: 32
    787.8 hours since Warbama declared Viet Nam II.
    Warbama: An LBJ for the Twenty-First century. No hope. No change.
    Lars Eighner, Jan 3, 2010
    #10
  11. Cat 22

    Doug Miller Guest

    In article <hhqrtt$s6o$-september.org>, Cat 22 <> wrote:
    >Doug Miller wrote:
    >
    >> In article <hhoq44$cb7$-september.org>, Cat 22
    >> <> 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.

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


    Did you try it????
    Doug Miller, Jan 3, 2010
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Treseler

    [Fwd: Vhdl dynamic generation]

    Mike Treseler, Jun 25, 2003, in forum: VHDL
    Replies:
    2
    Views:
    2,228
    abida
    Apr 17, 2011
  2. moondaddy
    Replies:
    3
    Views:
    545
    Steven Cheng[MSFT]
    Jul 1, 2004
  3. =?Utf-8?B?cGJi?=

    Dynamic Image Generation Service VB 1.1

    =?Utf-8?B?cGJi?=, Feb 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    348
    =?Utf-8?B?cGJi?=
    Feb 15, 2005
  4. Waverider
    Replies:
    1
    Views:
    191
    JuanDG
    Sep 21, 2004
  5. John W. Long

    HTML Generation (Next Generation CGI)

    John W. Long, Nov 22, 2003, in forum: Ruby
    Replies:
    4
    Views:
    328
    John W. Long
    Nov 24, 2003
Loading...

Share This Page