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 | [reply] [Watch: Dir/Any] [d/l] |
I seem to remember having seen people achieve something similar with JavaScript. I'm not really sure. Whatever, even if so then the same portability problems would arise...
| [reply] [Watch: Dir/Any] |
I have used preloading of images in javascript on some pretty big sites. It is worth a look. SOmething similar can be done with CSS.
jdtoronto
| [reply] [Watch: Dir/Any] |
Hrm... I guess I will just leave it be for now. Thanks for the info! | [reply] [Watch: Dir/Any] |