Can image be loaded without loading profiles?

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
johnbuuck
Posts: 5
Joined: 2014-06-20T12:44:51-07:00
Authentication code: 6789

Can image be loaded without loading profiles?

Post by johnbuuck »

I am encountering some images that contain some very large profiles that I have no need of. Sometimes they fail to load resulting in an exception from Magick::Image.read(), and sometimes they succeed and take up a lot of memory causing my more important allocation of a pixels buffer (that I pass to Magick::Image.write()) to fail.

It looks like I can call strip() after read() to discard such profiles before allocating my pixels buffer and I also see the ping() method that could be used to just access number of rows and columns without loading profiles (but that won't leave the Image in a state where I can call Write() to fill my pixels buffer).

Is there a way to have ImageMagick load the image such that I can get the pixel data without ever loading the profiles?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can image be loaded without loading profiles?

Post by fmw42 »

From http://www.imagemagick.org/Usage/formats/#jpg_read, it would appear that you can use +profile or -strip before reading a jpg to strip the profiles and/or other meta data while reading in the file. But I have not tested that, nor do I know if that would be any faster.

So you would have to test or get a reply from one of the IM developers.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can image be loaded without loading profiles?

Post by magick »

We can support this request with a simple patch, something like -define jpeg:skip-profile ICC, for example. Which image formats do you need to skip profiles? JPEG, TIFF, etc? Can you post a URL to a few of your images with large profiles so we can test the patch?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can image be loaded without loading profiles?

Post by fmw42 »

magick wrote:We can support this request with a simple patch, something like -define jpeg:skip-profile ICC, for example. Which image formats do you need to skip profiles? JPEG, TIFF, etc? Can you post a URL to a few of your images with large profiles so we can test the patch?

Is it possible (or practical) to do this for any image without specifying the image type? For example doing it in a loop over many images (or with mogrify), such that one does not need to get the image type before using this command?

such as

Code: Select all

-define all:skip-profile *
This is just a thought that might be useful, at least as an option. If one wants to limit it to image type and type of profile, that is also fine.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can image be loaded without loading profiles?

Post by magick »

Not that many image formats support profiles, so jpeg:skip-profile, tiff:skip-profile is reasonable. We prefer specific namespaces. However, if we find we are support this functionality in many image formats, a more general namespace is called for.
johnbuuck
Posts: 5
Joined: 2014-06-20T12:44:51-07:00
Authentication code: 6789

Re: Can image be loaded without loading profiles?

Post by johnbuuck »

I should clarify that I am using the term "Profiles" as it is used within a certain portion of the ImageMagick code rather than in the more narrow sense of published standard profiles like ICC, EXIF. Specifically, I am concerned with TIFF images and the TIFFGetProfiles() method of tiff.c which includes the loading of the "tiff:37724" TIFF tag which contains PhotoshopLayerData. Here is a link to an example file: https://drive.google.com/file/d/0BwGVQe ... sp=sharing.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Can image be loaded without loading profiles?

Post by snibgo »

You might also use exiftool to pre-process files, eg:

Code: Select all

exiftool -Photoshop:All= dst.jpg
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Can image be loaded without loading profiles?

Post by glennrp »

Years ago there were three types of profile that ImageMagick's PNG decoder would recognize: "ICC", "IPTC", and "generic". Now only "ICC" and "generic" remain, with IPTC being a type of "generic" profile. In a PNG input file, "generic" profiles are carried inside the zTXt or iTXt chunk, hex-encoded. Color profiles can be conveyed in either the zTXt or iTXt chunk (as hex-codes) or in the iCCP chunk. Simple color profiles can also be conveyed via the gAMA, cHRM, and sRGB chunks. EXIF is a type of "generic" profile. Adobe "XMP" profiles are conveyed via the iTXt chunk.

Simplest to implement would be an all-or-none choice:
-define png:skip-profiles
if present, skips all profiles and if absent keeps all profiles.
More complex:
-define png:skip-profiles=generic
-define png:skip-profiles=icc
Post Reply