Dimensions of an image file?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Dimensions of an image file?

Post by thatkeith » Sun Mar 18, 2018 9:07 pm

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' :D

But is there a way to do this (find the pixel width and height of a given image file) natively in LC?

k
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Dimensions of an image file?

Post by Klaus » Sun Mar 18, 2018 9:20 pm

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

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Dimensions of an image file?

Post by thatkeith » Sun Mar 18, 2018 11:28 pm

Wow - when in doubt, shell. :D

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
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Dimensions of an image file?

Post by Klaus » Mon Mar 19, 2018 11:36 am

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

Post Reply

Return to “Talking LiveCode”