Does shell s/w exist to determine the width & height of a JPEG?

Discussion in 'Apple' started by osiris, Oct 22, 2006.

  1. osiris

    osiris Guest

    Does a shell program exist to determine the dimensions of a JPEG?

    /usr/bin/file outputs the dimensions of a PNG:

    $ file myfile.png
    PNG image data, 72 x 72, 8-bit/color RGBA, non-interlaced

    but not for a JPG:

    $ file myfile.jpg
    JPEG image data, JFIF standard 1.01

    /sw/bin/convert (part of DarwinPorts and Fink) has a -size option
    but that, along with all other options, does not appear to
    provide information about a JPEG.

    Thanks for any help.
    osiris, Oct 22, 2006
    1. Advertisements

  2. osiris

    Eric Lindsay Guest

    man sips
    Eric Lindsay, Oct 22, 2006
    1. Advertisements

  3. osiris

    TaliesinSoft Guest

    One can see the dimensions of a JPEG directly in a Finder window. Open a
    Finder Window, select "Show View Options" in the View menu, and then in the
    resulting panel click on "Show Item info" and "All Windoes". Then when a
    Finder window is open in icon view each icon that is a TIFF or JPEG will have
    the pixel dimensions shown underneath the file name for that icon.
    TaliesinSoft, Oct 22, 2006
  4. osiris

    Tom Stiller Guest

    True, but the OP specifically asked for a shell method, presumably to
    incorporate it into a script.
    Tom Stiller, Oct 22, 2006
  5. osiris

    TaliesinSoft Guest

    Agreed that the OP asked for a "shell program" but I posted my response as a
    "just in case" answer.
    TaliesinSoft, Oct 22, 2006
  6. Agreed that the OP asked for a "shell program" but I posted my
    response as a "just in case" answer.[/QUOTE]

    Here's a plain vanilla Applescript as another just in case:

    set foo to choose file
    tell application "Image Events"
    set bar to open foo
    set the_dimensions to dimensions of bar
    close bar
    on error msg
    close bar
    log msg
    end try
    end tell
    Michelle Steiner, Oct 22, 2006
  7. osiris

    Jon Guest

    It also has to mean that the information is there somewhere, in the file
    or attached to it as metadata, and potentially could be read by a CLI
    util of some sort, I would think? Just spinning on the same thread here.
    Jon, Oct 22, 2006
  8. osiris

    Tom Stiller Guest

    Of course it is and 'sips', as previously mentioned will display it.
    sips -g pixelWidth -g pixelHeight /Users/tms/Pictures/Blacklist\ Ball\
    /Users/tms/Pictures/Blacklist Ball Honoree.jpg
    pixelWidth: 1253
    pixelHeight: 862
    Tom Stiller, Oct 22, 2006
  9. osiris

    osiris Guest

    Perfect! Thanks a million, Tom!
    If anybody knew, I kinda thought you would.

    Isn't /sw/bin/convert just Fink (and DarwinPorts) simply distributing
    one of ImageMagick's shell programs? ImageMagic has so many programs
    and so many options that I couldn't find a 'get info' in all of it.
    Thanks again!
    osiris, Oct 22, 2006
  10. osiris

    Tom Stiller Guest

    Thanks, but it was another poster (I disremember who) that first
    mentioned sips. I just repeated the recommendation because it matched
    the request for ashell command.
    You're right about convert being a component of ImageMagick, but sips is
    part of the Mac OS X distribution.
    Tom Stiller, Oct 23, 2006
  11. osiris

    Ian Gregory Guest

    I typed "man sips" and there was no man page, so I foolishly
    assumed that it was not available in 10.3. But it is there
    in /usr/bin and you can get some help with "sips --help".
    I am glad I found out about this, it may well prove useful.

    Currently I use cjpeg, djpeg, jpegtran etc for doing stuff
    with jpegs. They are available in the "jpeg" port from MacPorts
    (formerly known as DarwinPorts):

    | dune$ port info jpeg
    | jpeg 6b, Revision 1, graphics/jpeg
    | This distribution contains the sixth public release of the
    | Independent JPEG Group's free JPEG software.....

    I use these to reduce the size of photos for use on web pages

    djpeg -scale 1/2 big.jpeg|cjpeg > small.jpeg

    But there didn't seem to be a way to get the image size from
    any of the commands in the port.

    Ian Gregory, Oct 23, 2006
  12. osiris

    osiris Guest

    I have one more question. Suppose I have slideshow of JPEGs on the web
    and the slideshow reels off all the landscape images (4x3 aspect ratio)
    and then suddenly finds a portrait image (3x4 aspect ratio).
    The portrait image will then, of course, appear distorted as if
    in a circus mirror. Thus, is there any shell software that can be used
    to extend the canvas size of the portrait so that it becomes a landscape?
    What I mean by this is ...

    If the portrait is say 768x1024 (3x4 aspect ratio),
    can blank canvas be added with something like /sw/bin/convert
    to make it into a 1365x1024 image (with 4x3 aspect ratio)?

    This can easily be done in Photoshop but I'd like to do it
    programmatically in the script itself. Thanks.

    osiris, Oct 23, 2006
  13. osiris

    Doc O'Leary Guest

    Also worth mentioning, as of 10.4, is mdls (e.g., mdls -name
    kMDItemPixelHeight -name kMDItemPixelWidth). It gives image dimensions,
    but is also very useful in working with metadata of other file types.
    Doc O'Leary, Oct 23, 2006
  14. osiris

    Tom Stiller Guest

    Does your MANPATH environment variable include '/usr/share/man/'?

    Tom Stiller, Oct 23, 2006
  15. osiris

    Paul Sture Guest

    Same here, no no man page, but I found this link:
    Paul Sture, Oct 23, 2006
  16. osiris

    Paul Sture Guest

    Paul Sture, Oct 23, 2006
  17. osiris

    Tom Stiller Guest

    Tom Stiller, Oct 23, 2006
  18. osiris

    Paul Sture Guest

    Oop - I seem to have missed this bit of info...

    I found the sips man page on the web:

    Paul Sture, Oct 23, 2006
  19. osiris

    Simon Slavin Guest

    Not 'of course' at all. It depends on how the software is written. I
    feel that that wouldn't be the correct behaviour so if I wrote a slideshow
    program it wouldn't do this. In fact, the one built into OS X doesn't do

    In the Finder, select a few image files with different aspect ratios.
    Control-click on one of them.
    Choose 'Slideshow' from the menu.

    Simon Slavin, Oct 26, 2006
  20. osiris

    Simon Slavin Guest

    Works fine for me:

    sips(1) BSD General Commands Manual

    I suspect you have 'fink' installed. The 'fink' installer screws up your

    Simon Slavin, Oct 26, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.