creating and presenting an image in php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Wedd

    creating and presenting an image in php

    Maybe this isn't really a PHP problem. But it's possible that PHP has a
    good solution for it.

    I have a php page which collects some input from the user, constructs an
    image, and then displays it to the user. The line of php that does the
    actual presentation to the user is
    print "<a href='$string'> <img src='$string' width=784 height=431
    border=0></a>\n";
    where $string is something like
    'r.pl?ar=7;cl=1 0'
    so the user gets to see a (large) thumbnail, and can then click on it to
    see the full-sized version.

    (The actual nitty-gritty of the image creation is done in Perl not PHP.
    I wrote it before I became more familiar with PHP and learned that PHP
    uses the GD library. I could rewrite it into PHP if I have to.)

    My problem is that my code calls r.pl twice, to do the same thing: once
    when the page is created, and once when the user clicks on the image.
    This wastes quite a bit of cpu time on the server, and slows the
    response for the user. What I would prefer to do is call r.pl once, put
    the resulting image in some kind of temporary session-specific file on
    the server (or in its memory), and then use this temporary thing twice,
    in place of $string above. Is this somehow possible?

    Nick
    --
    Nick Wedd nick@maproom.co .uk
  • Erwin Moller

    #2
    Re: creating and presenting an image in php

    Nick Wedd wrote:
    Maybe this isn't really a PHP problem. But it's possible that PHP has a
    good solution for it.
    >
    I have a php page which collects some input from the user, constructs an
    image, and then displays it to the user. The line of php that does the
    actual presentation to the user is
    print "<a href='$string'> <img src='$string' width=784 height=431
    border=0></a>\n";
    where $string is something like
    'r.pl?ar=7;cl=1 0'
    so the user gets to see a (large) thumbnail, and can then click on it to
    see the full-sized version.
    >
    (The actual nitty-gritty of the image creation is done in Perl not PHP.
    I wrote it before I became more familiar with PHP and learned that PHP
    uses the GD library. I could rewrite it into PHP if I have to.)
    >
    My problem is that my code calls r.pl twice, to do the same thing: once
    when the page is created, and once when the user clicks on the image.
    This wastes quite a bit of cpu time on the server, and slows the
    response for the user. What I would prefer to do is call r.pl once, put
    the resulting image in some kind of temporary session-specific file on
    the server (or in its memory), and then use this temporary thing twice,
    in place of $string above. Is this somehow possible?
    >
    Nick
    Yes Nick,

    Excactly as you described it it could be done.
    Just search for image (in the functionsearch) at www.php.net and you'll find
    plenty examples.

    Many imagefunctions have the possibility to safe the image to a path or
    serve them directly to the browser.
    If you run into problems, just come back here.

    Good luck,

    Regards,
    Erwin Moller

    Comment

    • Nick Wedd

      #3
      Re: creating and presenting an image in php

      In message <45bf29dc$0$324 $e4fe514c@news. xs4all.nl>, Erwin Moller
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c omwrites
      >Excactly as you described it it could be done.
      >Just search for image (in the functionsearch) at www.php.net and you'll find
      >plenty examples.
      >http://nl2.php.net/manual/en/ref.image.php
      >Many imagefunctions have the possibility to safe the image to a path or
      >serve them directly to the browser.
      >If you run into problems, just come back here.
      I find that I can do all the image-processing stuff, e.g.
      <?php
      $im = imagecreatefrom png("i/sea.png");
      // many image-processing commands
      imagepng($im, "foo.png");
      ?>
      <a href='foo.png'> <img src='foo.png' width=80 height=60></a>

      What I still don't know is how to use a temporary file, that will go
      away when the user leaves the page, to store either the image or
      header+image.

      Nick
      --
      Nick Wedd nick@maproom.co .uk

      Comment

      • Erwin Moller

        #4
        Re: creating and presenting an image in php

        Nick Wedd wrote:
        In message <45bf29dc$0$324 $e4fe514c@news. xs4all.nl>, Erwin Moller
        <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c omwrites
        >>Excactly as you described it it could be done.
        >>Just search for image (in the functionsearch) at www.php.net and you'll
        >>find plenty examples.
        >>http://nl2.php.net/manual/en/ref.image.php
        >>Many imagefunctions have the possibility to safe the image to a path or
        >>serve them directly to the browser.
        >>If you run into problems, just come back here.
        >
        I find that I can do all the image-processing stuff, e.g.
        <?php
        $im = imagecreatefrom png("i/sea.png");
        // many image-processing commands
        imagepng($im, "foo.png");
        ?>
        Ok, good.
        <a href='foo.png'> <img src='foo.png' width=80 height=60></a>
        >
        What I still don't know is how to use a temporary file, that will go
        away when the user leaves the page, to store either the image or
        header+image.
        Well, the overhead needed to store temp image files, and the
        garbagecollecti on to find them and remove old ones, is probably not worth
        your time.
        Why not simply recreate it? Are you charged per CPU-cycle? ;-)

        But if you want to do it you have several options, depending on what it is
        excactly that you want to achieve.
        Is each image you create unique for each visitor?
        Do you want different visitor to be able to share images?
        Or is your image ONLY valid when created as thumbnail, and then again as big
        picture? Should some images be deleted, and others not? And what are the
        rules?

        You could think up some scheme where you store them in a directory, but if
        nobody clicks through to the big picture, that directory will soon be
        filled with nonsense images. You'll have to make some cronjob to clean that
        up based on creationtime.

        I would simply go with the doublecreation: your original plan. Clean and
        simple.

        Regards,
        Erwin Moller

        >
        Nick

        Comment

        Working...