Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How can I get image height and width without using Image::Size?

( #28183=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Aug 16, 2000 at 23:25 UTC
Q&A  > files


Description:

Update by Corion for QAndAEditors

Anonymous Monk had to add the following to his question :

I don't know if my way to use Image::Size is wrong. What's wrong? Here is my code:

#!/usr/bin/perl use CGI qw(:standard); use Image::Size; my @temp=(); my $tmp=""; @temp = imgsize("boy1.jpg"); print header(); foreach $tmp(@temp) print "$tmp";

Answer: How can I get image height and width without using Image::Size?
contributed by lhoward

There are several other modules other than Image::Size that you can use to get the height and width of an image. You could try Image::Info or Image::Magick.

But if you want to avoid using modules entirely you're going to have to learn how to read image headers. The headers are different for different types of images (.jpg, .png, etc...). But in general most image files have the height and width stored (generally as 16 or 32 bit integers) somewhere within the first 100 bytes or so of the image.

Answer: How can I get image height and width without using Image::Size?
contributed by fundflow

I sometimes use the `file` command - it's output is easy to parse and can deal efficiently with many images.

The problem is that it is not very standard and so my linux version gives more details than the solaris one

Answer: How can I get image height and width without using Image::Size?
contributed by Anonymous Monk

I have put the curly braces around the codes.. but it doesn't work. Here is the error message: Can't locate Image/Size.pm in @INC What can I do??

Answer: How can I get image height and width without using Image::Size?
contributed by Anonymous Monk

I have put the curly braces around the codes.. but it doesn't work. Here is the error message: Can't locate Image/Size.pm in @INC What can I do??

Answer: How can I get image height and width without using Image::Size?
contributed by rapidwiz

I like Image::Size. (However, I was unable to get it working on an older RedHat system due to missing modules.) You should use it if you can because it is much more efficient, as it doesn't spawn a process. Here's how:

use Image::Size; # get the image size, and print it out my( $width, $height ) = imgsize( $imagefile_pathname );

But if you want to do it purely using a system command and ImageMagick's identify, here's how:

# (assume identify is in the path) chomp( my $ident = `identify -format "%w %h" "$imagefile_pathname"` ); my( $width, $height ) = split ' ', $ident;
Answer: How can I get image height and width without using Image::Size?
contributed by Corion

The problems stated after the question could be solved by looking at what Perl prints in response to the above code :

syntax error at tmp.pl line 14, near ") print" Execution of tmp.pl aborted due to compilation errors.

Which means that Perl does want curly braces around the code to be processed in a foreach loop.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (10)
    As of 2014-12-18 21:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (66 votes), past polls