Fast way to get Image Info (size, datatype info)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
nicolas1

Fast way to get Image Info (size, datatype info)

Post by nicolas1 »

Is there any way to get image dimensions and datatype data (located usually in image file header) fastly? "ping" function reads whole imagefile into memory and then return this data. This causes significan and not necessary delay...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fast way to get Image Info (size, datatype info)

Post by fmw42 »

identify <image>

or for more information

identify -verbose info: <image>
nicolas1

Re: Fast way to get Image Info (size, datatype info)

Post by nicolas1 »

Inspecting source I found that "identify" uses "PingImage" internally.

I mean function which read only image header... not a whole imagefile (do not confuse reading with decoding).
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Fast way to get Image Info (size, datatype info)

Post by magick »

PingImage() reads the entire image but throws the pixels away so it is fast and memory efficient. ImageMagick does not have a method to just read an image header but not the pixels.
nicolas1

Re: Fast way to get Image Info (size, datatype info)

Post by nicolas1 »

"PingImage" is much faster then decoding, but noticable slow then just read header. For example, if jpeg image is 16 megs, delay is significant. Maybe better to have api, which is invariant of image size. Just a suggestion.
For example, usually it is necessary to make some precalculations depending on image size, before really decoding it. The faster way to get image size before docoding, results in more interactive program.

Btw, it is possible to modify current IM code ("ReadImage" fucntion)?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Fast way to get Image Info (size, datatype info)

Post by magick »

JPEG is a special case. Set the image_info->size member to something small like 16x16 and PingImage() will return quickly.
Post Reply