Page 1 of 1
Dimensions of an image file?
Posted: Sun Mar 18, 2018 9:07 pm
by thatkeith
I'm working on a tool that will help my students understand image resolution in relation to page layout for print. One thing I need to do is find the pixel dimensions (width, height) of any given image file: JPEG, TIFF, PSD and other bitmap image formats.
I'm getting somewhere with AppleScript, although dealing with file paths across LC and AS is, er, 'interesting'
But is there a way to do this (find the pixel width and height of a given image file) natively in LC?
k
Re: Dimensions of an image file?
Posted: Sun Mar 18, 2018 9:20 pm
by Klaus
Hi Keith,
on the Mac you can use SIPS (Scriptable Image Processing System) with shell!
Use something like this to get the dimensions of any image:
Code: Select all
on mouseUp
answer file "Select image..."
put QUOTE & it & QUOTE into tImage
get shell("sips -g pixelHeight" && tImage)
put last word of it into tHeight
get shell("sips -g pixelWidth" && tImage)
put last word of it into tWidth
answer "Image dimensions:" && tWidth & "," & tHeight
end mouseUp
Best
Klaus
Re: Dimensions of an image file?
Posted: Sun Mar 18, 2018 11:28 pm
by thatkeith
Wow - when in doubt, shell.
I had a bit of a search for a CLI solution (honest, I did!) but I was too hung up on my 'close but no cigar' efforts with AppleScript. This is superb and easy to weave into my experiments – many thanks!
k
Re: Dimensions of an image file?
Posted: Mon Mar 19, 2018 11:36 am
by Klaus
Hi Keith,
glad I could help!
And SIPS can do a lot more with images, see the MAN page here:
https://developer.apple.com/legacy/libr ... ips.1.html
And yes, AppleScripts SUCKS, hard to believe that HyperTalk was intended to be the first Scripting language for Mac OS, but then they chose AppleScript
Anyway, have a nice day!
Best
Klaus