Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 3 of 3

This is a discussion on Perl - Grab image size? in the Shared & Semi-Dedicated forum
Hi there. I'm a beginer in Perl, and I wrote this kind of dynamic catalog for this customer of mine which sells framed images. I ...

  1. #1
    Loyal Client
    Join Date
    Aug 2002
    Posts
    269

    Perl - Grab image size?

    Hi there. I'm a beginer in Perl, and I wrote this kind of dynamic catalog for this customer of mine which sells framed images. I used MySQL and everything is working great. There is one little detail I'd like to do, but it's not the end of the world if it isn't possible.

    I show these images as thumbnails, and if a person clicks on the thumbnail, I open a new window with a larger sized image in it. That larger sized image varies greatly and there are 600 images. When I open in a new window, I'd like to set the width/height of that new window to match the size of the image so the user isn't having to always resize each time a window opens. Is there any way to get those parameters from within Perl?

    Although it isn't totally done yet, you can check it out at www.art4kids.com/simplecatalog.html

    Thanks
    Sam

  2. #2
    Loyal Client
    Join Date
    Aug 2002
    Posts
    269
    Duh! Actually I found the info myself. It was the first thing that popped up on a Google search. It is using the Image::Size module.

    But I didn't really know how to use it, and found this site that gave a working example, but it doesn't work. Our Perl here says the module is included.

    This is the entire test Perl file I used (I changed test.jpg to a known image location).

    #!/usr/bin/perl -w
    use strict;
    use Image::Size;

    # Just fetch the size
    my ($size_x, $size_y) = Image::Size::imgsize("test.jpg");
    print "Image is: $size_y x $size_x (height x width)\n";

    # HTML-friendly format
    my $size = Image::Size::html_imgsize("test.jpg");
    print "Here is my image <img src=\"test.jpg\" $size>\n";

    exit();

    I got a 500 error, and then added:

    print "Content-type:text/html\n\n";

    The error went away and the output I got was:

    Image is: x (height x width)

    I'm 100% positive of the location of the jpeg file. I tried several different ones relative and with the full address and get the same thing. Anyone?

  3. #3
    JPC Senior Member
    Join Date
    Sep 2001
    Posts
    50
    Image::Size has pod documentation that gives a more complete overview, but
    in a nutshell:

    use Image::Size;

    ($x, $y) = imgsize("something.gif");

    And ($x, $y) is now the width and height of something.gif.
    --
    Alien Heat - Affordable Web Hosting and Design
    http://www.AlienHeat.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •