Hello,

I know it is over a year later, but this post helped me solve my own problem - wanting to create various sizes of images, or even to scale images to a constant size.

It sounds like since your script generates HTML and images both, you want a way to embed the binary images into the HTML. I am not sure I know of a way to do that. I have done scripts where you use a parameter to trigger an image or HTML based upon the value of the parameter, and then just call the script with the parameter indicating "image" from the page generated by the script in "HTML" mode.

Or, you could split the script into two separate scripts. I know, not very clean.

For those interested in my resizing-on-the-fly solution, it is here:
#!/usr/local/bin/perl # Usage: http://www.yoururl.com/cgi-bin/image_resize.cgi?FILE=/path/to +/image.jpg&SIZE=300 use Image::Resize; use Image::Size; use CGI::Simple; my $q = new CGI::Simple; my $file = $q->param('FILE'); # Path to file on server file system my $size = $q->param('SIZE'); # Desired size of image my ($x, $y, $type) = imgsize($file); $size = ($x > $y) ? $x : $y if (($x < $size) || ($y < $size)); # Will not scale greater than 100% my $image = Image::Resize->new($file); my $gd = $image->resize($size, $size, 1); # 1 = maintain aspect ratio binmode STDOUT; if ((uc($type) eq 'JPG') || (uc($type) eq 'JPEG')) { print(qq|Content-Type: image/jpeg\n\n|); print $gd->jpeg(); } elsif (uc($type) eq 'PNG') { print(qq|Content-Type: image/png\n\n|); print $gd->png(); } elsif (uc($type) eq 'GIF') { print(qq|Content-Type: image/gif\n\n|); print $gd->gif(); }
I hope this is useful to someone. Enjoy!

Regards,

Mark, Webberville, Michigan USA

In reply to Re^2: Dymanically Generated Images in Website by PerlPilgrim
in thread Dymanically Generated Images in Website by debiandude

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.