Resizing PNG with color profile, without damaging colors, for upload to profile-unaware service

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
Malloc Voidstar
Posts: 2
Joined: 2016-03-23T18:23:48-07:00
Authentication code: 1151

Resizing PNG with color profile, without damaging colors, for upload to profile-unaware service

Post by Malloc Voidstar »

Using ImageMagick 7.0.0-0 Q16 x64 2016-03-13 (HDRI enabled) on Win7.

I am attempting to devise the proper commandline for resizing an image with color profile for upload to Tumblr, which allows color profiles but does not understand them. Fullsize profiled images look fine if untouched (fitting within resolution/size constraints) but thumbnails look bad. I can do this with Photoshop, but cannot find a way to reproduce it with ImageMagick.

Example image: https://40.media.tumblr.com/5ee6c33a4ed ... 1_1280.png
Thumbnail: https://40.media.tumblr.com/5ee6c33a4ed ... o1_540.png
This is a PNG I saw and noticed issue on, with ICC profile. Note how Tumblr's resize system has damaged colors. (I am testing in FF/Chrome/IE10 on color-profiled monitor)

If I try to scale using my current commandline:

Code: Select all

magick input.png -colorspace RGB -filter Lanczos -define filter:blur=.9891028367558475 -distort Resize 714x1009 -colorspace sRGB scaled.png
then the resulting image has the washed out colors in Firefox/Chrome/Photoshop.
(size param is width-1 to make color change obvious, not resolution; other options are taken from Robidoux's recommendations)

I have tried some combinations of -profile option but none of them result in quality as high as Photoshop.

Opening in Photoshop and using Save For Web, resizing to 714x1009, choosing "Embed color profile" and "Convert to sRGB" results in a thumbnail that looks much better (not perfect) and an accurate fullsized image.
Is there any way I can reproduce this with ImageMagick or improve on it?
I have a semi-automated system for processing/upload and this issue prevents it from properly running without human supervision.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing PNG with color profile, without damaging colors, for upload to profile-unaware service

Post by fmw42 »

Code: Select all

identify -verbose tumblr_o4f6mpGacT1unm603o1_1280.png
show the image has a Cintiq 24HD_Easy_D65.icc profile

Add the same (Cintiq 24HD_Easy_D65.icc) profile as in your input to your scale.png before saving by including -profile path2/Cintiq 24HD_Easy_D65.icc.

Copy the profile from the input and save it first.

Code: Select all

convert tumblr_o4f6mpGacT1unm603o1_1280.png icc:Cintiq 24HD_Easy_D65.icc
Or avoid using -colorspace RGB .... -colorspace sRGB.

This works fine for me.

Code: Select all

convert tumblr_o4f6mpGacT1unm603o1_1280.png -resize 714x1009 scaled.png
Either way that should make the original and the scaled images at least look the same.

I do not know how to change the image so that it gets the color of the profile without having a profile.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing PNG with color profile, without damaging colors, for upload to profile-unaware service

Post by snibgo »

I see the version resized by tumblr, and both versions from Photoshop, have no embedded profile.

I read somewhere that Photoshop's "Save for Web" converts images that have embedded profiles to sRGB. That's what I would do with IM.

Code: Select all

convert tumblr_full_im.png -profile sRGB.icc -strip t.png
snibgo's IM pages: im.snibgo.com
Malloc Voidstar
Posts: 2
Joined: 2016-03-23T18:23:48-07:00
Authentication code: 1151

Re: Resizing PNG with color profile, without damaging colors, for upload to profile-unaware service

Post by Malloc Voidstar »

Thanks for the assistance. I have encountered success, I think. Somehow I came to:

Code: Select all

magick input.png -profile sRGB_IEC61966-2-1_black_scaled.icc -colorspace RGB -filter Lanczos -define filter:blur=.9891028367558475 -distort Resize 714x1009 -colorspace sRGB -strip step1.png

magick step1.png -profile sRGB_IEC61966-2-1_black_scaled.icc output.png
Profile used is available here: http://www.color.org/srgbprofiles.xalter
It's the sRGB v2 profile and quite small. Using the sRGB.icc instead that ships with ImageMagick ('v4 preference') gave slightly wrong colors using same commandline. Not using a profile (-profile to get to sRGB then -strip) also gives slightly wrong colors.
This commandline results in a fullsize image that matches source/Photoshop, and a thumbnail that looks correct.
I don't think this is perfect of course (sample size of images too small), but it should still be improvement on my current method. Photoshop seems to use a Hewlett-Packard sRGB profile from 1998 that I cannot find a copy of, so I went with this.

Some thing I ran into:
Photoshop's full image does have an ICC profile, in iCCP chunk, but ImageMagick cannot extract it, claiming no profile. Identify can see the iCCP chunk but does not list a profile. Browsers use the profile correctly so I assume this is a bug in ImageMagick.
Using https://github.com/jsummers/deark I was able to extract it, but ImageMagick crashes when trying to use it (but identify does say it is a color profile).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing PNG with color profile, without damaging colors, for upload to profile-unaware service

Post by snibgo »

Malloc Voidstar wrote:Photoshop's full image does have an ICC profile, in iCCP chunk, but ImageMagick cannot extract it, claiming no profile. Identify can see the iCCP chunk but does not list a profile. Browsers use the profile correctly so I assume this is a bug in ImageMagick.
So it does, thanks. Perhaps a developer (glenrp?) can comment on whether IM should read it.

It can be extracted by exiftool, then used by IM, eg:

Code: Select all

exiftool -o x.icc tumblr_full_ps.png

convert tumblr_full_ps.png -profile x.icc -profile sRGB.icc p.png
snibgo's IM pages: im.snibgo.com
Post Reply