extracting thumbnail from exif headers

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
eastern_strider

extracting thumbnail from exif headers

Post by eastern_strider »

I was wondering if there is a function in Magick++ which returns the thumbnail image stored in an EXIF header (for JPEG and TIF files).

I'm developing a GUI application where I need to display thumbnails of multiple images rapidly. Reading the whole image and scaling down to create thumbnails works too slow for my purposes.

Thanks,
eastern_strider
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: extracting thumbnail from exif headers

Post by magick »

Write to a blob in the thumbnail: image format. As you may have guessed, the thumbnail: image format is the thumbnail extracted from the EXIF profile.
eastern_strider

Re: extracting thumbnail from exif headers

Post by eastern_strider »

Do you mean something like that?

Image image("test.jpg");

Blob blob;
image.write(&blob, "thumbnail:JPEG");

Image image2(blob);
image2.write("thumb.jpg");

But in this case the output image becomes the same size as input image.

I also tried image.write(&blob, "thumbnail: JPEG") . This gives "zero-length blob not permitted" exception.

What am I doing wrong? (I'm certain that the image has thumbnail in the exif header).
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: extracting thumbnail from exif headers

Post by magick »

Start with
  • convert test.jpg thumbnail:thumb.jpg
Does that produce a thumbnail image? It does for us. If not try upgrading your version of ImageMagick. If it still fails, post a URL to your image here so we can download and determine why the thumbnail is not being read.
eastern_strider

Re: extracting thumbnail from exif headers

Post by eastern_strider »

convert test.jpg thumbnail:thumb.jpg does produce thumbnail. The magick++ API does not. I'm probably not using the magick++ functions properly. But I've uploaded the file at http://www.coolhall.com/homepage/files/test.jpg in case you'd like also like to try.

One issue though. Even if this works, it seems that the entire image is read when we create the image. The call:

Image image("test.jpg");

reads and decodes the whole JPEG file isn't it? Wouldn't it be much slower than just reading the thumbnail?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: extracting thumbnail from exif headers

Post by magick »

If all your images are JPEG you can set the image_info->size attribute to something like 160x160 and ImageMagick will only create a small image internally. However, the most efficient implementation would extract the EXIF profile directly and extract the thumbnail, however ImageMagick does not directly provide an interface to just extract the EXIF profile without reading the image pixels.
eastern_strider

Re: extracting thumbnail from exif headers

Post by eastern_strider »

Okay, thanks for the clarification.
eastern_strider

Re: extracting thumbnail from exif headers

Post by eastern_strider »

Thanks to Blob class efficient retrieval of thumbnail from Exif shouldn't be difficult in any case. It boils down to locating the position and size of the thumbnail, reading it as a binary chunk from the disk and passing the result to a blob.

I think ImageMagick might already be supporting retrieving these information. I see exif:ThumbnailData and exif:ThumbnailSize tags in property.c
Post Reply