http://qs1969.pair.com?node_id=260590

Hagbone has asked for the wisdom of the Perl Monks concerning the following question:

Oh wise ones ....

I have a

use Image::Magick;

question concerning creating thumbnails on the fly. I'm able to produce an on-the-fly thumbnails (snippet below), and an essential part of the code is using the proper Content-type line.

print "Content-type: image/gif\n\n"; binmode STDOUT; $thumb->Write('gif:-');
The above works fine, but my question/problem has to do with how to structure a script so it will produce *both* html content and thumbnails images in one output session.

If I use

print "Content-type:text/html\n\n"; <code> the html displays fine, but the images appear as binary code. If I use + the <code> print "Content-type: image/gif\n\n";
The html will not display.

I've cobbled a work around by creating temporary thumbnail images, and pointing to them in the html code, but would really like to know if there is a way to do what I describe above using on-the-fly images.

All suggestions appreciated

Replies are listed 'Best First'.
(jeffa) Re: combining html and on-the-fly images using Image::Magick
by jeffa (Bishop) on May 24, 2003 at 15:22 UTC
    You could write a second CGI script that accepts a argument for the gif to display (say , display.cgi). The first script then simply creates HTML, and any reference to a dynamic image will look like:
    <img src="/path/to/display.cgi?name=foo" alt="foo" />
    But if you have a lot of these ... that's a lot of CGI hits on the server. I would consider 'bulk generating' the images via a cron job if server performance becomes an issue (unless they are very 'on the fly' of course).

    Also, consider using CGI.pm's header method to simplify printing content headers:

    usg CGI qw(header); print header; print header('image/gif');

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
•Re: combining html and on-the-fly images using Image::Magick
by merlyn (Sage) on May 24, 2003 at 16:09 UTC
Re: combining html and on-the-fly images using Image::Magick
by jepri (Parson) on May 24, 2003 at 15:51 UTC
    To clarify jeffa's response, you can't do what you want to do. Images in html are just links that the browser automatically downloads. There is a separate connection for every image. So what you are doing is more or less right.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

        That is indeed a cool trick, and is much needed, but I can't see any specs for it at w3c.org, which makes me think it is browser specific and therefore A Bad Thing, regardless of how cool it is.

        (Standards are everything. Obey the w3c. The w3c is your friend.)

        Update: the w3c has nothing to say on the matter, but the IETF does (as mentioned below in this thread). So yay to that. ____________________
        Jeremy
        I didn't believe in evil until I dated it.

Re: combining html and on-the-fly images using Image::Magick
by revdiablo (Prior) on May 25, 2003 at 04:58 UTC