Page 1 of 1

get the width and height of an image file all types

Posted: Fri Nov 23, 2012 11:21 am
by jmburnod
Hi All,
We have a function that return the width and height of a .png file.
http://forums.runrev.com/phpBB2/viewtop ... =8&t=12386
What about other types (jpg,tiff etc..) ?
Can we use the same way and what is the magic string to search ?
Best regards
Jean-Marc

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 11:25 am
by Mark
Hi Jean-Marc,

You can use ImageMagick.

Kind regards,

Mark

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 3:00 pm
by jmburnod
Hi Mark,
Do you think imagemagik's library using by LiveCode ?
Kind regards
Jean-Marc

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 3:08 pm
by Mark
Hi Jean-Marc,

I'm not sure what you mean, but I use ImageMagick with LiveCode (sometimes).

Kind regards,

Mark

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 4:19 pm
by FourthWorld
jmburnod wrote:Hi All,
We have a function that return the width and height of a .png file.
http://forums.runrev.com/phpBB2/viewtop ... =8&t=12386
What about other types (jpg,tiff etc..) ?
Can we use the same way and what is the magic string to search ?
The method that converts the binary header info will of course require a different script for each image format, but if you're not too concerned about performance the method that loads the image and obtains the formattedWidth and formattedHeight of the image object will work easily with all image formats LiveCode supports.

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 8:30 pm
by jmburnod
FourthWorld wrote:
if you're not too concerned about performance the method that loads the image and obtains the formattedWidth and formattedHeight of the image object will work easily with all image formats LiveCode supports.
Yes. Performance was the goal. "reading binary" is the fastest

For 100 files .png
• Shell: 614 ticks
• set the filename: 42 ticks (with lockscreen)
• reading binary: 2 ticks

reading binary
12 ticks for 4792 image files
27 ticks for 7385 image files

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 8:31 pm
by Mark
Hi,

I don't think there is a way to load TIFF images in LiveCode yet (which Jean-Marc asks about). You'll need a different solution for that and ImageMagick is just the thing.

Best,

Mark

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 8:42 pm
by jmburnod
Hi Mark,
I read the doc about imagemagic but i dont understand how can i use it with LiveCode. :oops:
I'll download it and i'm coming back
Kind regards
Jean-marc

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 9:13 pm
by FourthWorld
jmburnod wrote:For 100 files .png
• Shell: 614 ticks
• set the filename: 42 ticks (with lockscreen)
• reading binary: 2 ticks

reading binary
12 ticks for 4792 image files
27 ticks for 7385 image files
What shell command are you using for that?

Also, FWIW LiveCode supports millisecond timing, helpful for smaller measurements.

Re: get the width and height of an image file all types

Posted: Fri Nov 23, 2012 10:59 pm
by jmburnod
FourthWorld wrote:
What shell command are you using for that?

Code: Select all

on mouseUp
  answer file "Bild laden.../Load image..."
  put QUOTE & it & QUOTE into bild

## Get ehight of image:
  get shell("sips -g  pixelHeight" && bild)

## It is the last word
  put last word of it into hoch

## Same for width:
  get shell("sips -g  pixelWidth" && bild)
  put last word of it into breit
  put breit & "," & hoch into fld 1
end mouseUp

Re: get the width and height of an image file all types

Posted: Sat Nov 24, 2012 12:00 am
by FourthWorld
Thanks for that. I've not had occasion to use sips, but it seems worth knowing about.

If you wan to read the binary header info of any file format, the process would be the same as for PNG: you'll have to find the file format spec and parse it up, using LiveCode's binaryConvert function to translate values from the binary form into decimal for use in your scripts.

This will no doubt be tedious (somewhat more so with JPEG and TIFF than GIF, since those have variable resolutions), but doable.

Re: get the width and height of an image file all types

Posted: Sat Nov 24, 2012 11:13 am
by jmburnod
Thanks for that.
Welcome.
I've not had occasion to use sips, but it seems worth knowing about.
Me too before Klaus posted it

Re: get the width and height of an image file all types

Posted: Sat Nov 24, 2012 1:08 pm
by Klaus
Hi friends,

if QuickTIme is installed on the target machines, you could use a (QuickTIme) player object
to check all QT comaptible image file tpyes like TIFF, PSD etc..., too!

Just set the filename and check formattedwidth and formattedheight of the player.
With a "lock screen" this is as fast as using an image object in Livecode for JPG and PNG!


Best

Klaus