get the width and height of an image file all types

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

get the width and height of an image file all types

Post by jmburnod » Fri Nov 23, 2012 11:21 am

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
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

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

Post by Mark » Fri Nov 23, 2012 11:25 am

Hi Jean-Marc,

You can use ImageMagick.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod » Fri Nov 23, 2012 3:00 pm

Hi Mark,
Do you think imagemagik's library using by LiveCode ?
Kind regards
Jean-Marc
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

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

Post by Mark » Fri Nov 23, 2012 3:08 pm

Hi Jean-Marc,

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

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Fri Nov 23, 2012 4:19 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod » Fri Nov 23, 2012 8:30 pm

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
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

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

Post by Mark » Fri Nov 23, 2012 8:31 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod » Fri Nov 23, 2012 8:42 pm

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
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Fri Nov 23, 2012 9:13 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod » Fri Nov 23, 2012 10:59 pm

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
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Sat Nov 24, 2012 12:00 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod » Sat Nov 24, 2012 11:13 am

Thanks for that.
Welcome.
I've not had occasion to use sips, but it seems worth knowing about.
Me too before Klaus posted it
https://alternatic.ch

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post by Klaus » Sat Nov 24, 2012 1:08 pm

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

Post Reply