Convert: adding color profile does not work on Linux

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
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Convert: adding color profile does not work on Linux

Post by the-ninth »

Hi,

I am using ImageMagicks' convert command from a PHP application. I'd like to extract the color profile of a JPG, then strip it of all metadata and then put the color profile back in.

My code works fine on Windows, but on Linux the last step of putting the profile back in does not work. The return code is 0, but the target file does not have the profile. The exported ICC file is identical on Linux and Windows.

Here a sample code that I used for testing this:

Linux:

Code: Select all

system( '/usr/bin/convert -version', $ret );
system( '/usr/bin/convert source.jpg source.icc', $ret );
system( '/usr/bin/convert source.jpg -strip target_no_profile.jpg', $ret );
system( '/usr/bin/convert target_no_profile.jpg -set profile source.icc target_with_profile.jpg', $ret );
echo '</br>' . $ret;
Windows:

Code: Select all

system( 'd:\imagemagick\convert.exe -version', $ret );
system( 'd:\imagemagick\convert.exe source.jpg source.icc', $ret );
system( 'd:\imagemagick\convert.exe source.jpg -strip target_no_profile.jpg', $ret );
system( 'd:\imagemagick\convert.exe target_no_profile.jpg -set profile source.icc target_with_profile.jpg', $ret );
The version output is:

Linux:

Code: Select all

Version: ImageMagick 6.3.5 06/04/09 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC 
Windows:

Code: Select all

Version: ImageMagick 6.6.6-6 2010-12-18 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC Features: OpenMP 
I'd appreciate any hints on what I am doing wrong here.

Cheers, Robert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert: adding color profile does not work on Linux

Post by fmw42 »

Just a guess but you linux system version of IM is ancient and there is probably some bug that has been fixed since then. Can you upgrade your linux system?
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Convert: adding color profile does not work on Linux

Post by the-ninth »

Hi fmw42,

The Linux system is my hosting account. I send them an email about an ImageMagick update, but I am not expecting too much. On previous, similar occasion they told me I'd have to move my account to a new server and again setup everything (database, scripts) myself.

I tried to go a different way by removing everything apart from the profile. But again, this only works on Windows. Here the Linux version of the code:

Code: Select all

system( '/usr/bin/convert source.jpg +profile "!icc,*" target.jpg', $ret );
On Windows I get a file with similar size than with my previous approach, i.e. with everything removed but the profile. On Linux the target file has the same size as the source file, i.e. nothing was removed at all. I tried both with !icc an !icm, but the result is the same. :(

Cheers, Robert
Last edited by the-ninth on 2011-09-22T22:35:18-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert: adding color profile does not work on Linux

Post by fmw42 »

Sorry, I don't think I have any other suggestions, except upgrading. Perhaps some one else might have some further insight.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert: adding color profile does not work on Linux

Post by anthony »

I believe -thumbnail resize strips all profiles except the color profile, incase you want to save it into the same image file format.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Convert: adding color profile does not work on Linux

Post by the-ninth »

Hi,

Just tried Anthony's suggestion and again, this works on Windows/IM 6.6.6 but not on my Linux/IM 6.3.5 version. When doing -thumbnail 100%, then on 6.6.6 I get a file with everything stripped but the profile. On 6.3.5 I get a file with everything stripped, also the profile.

BUT: I found now that using -profile instead of -set profile works on 6.3.5!

Code: Select all

system( '/usr/bin/convert source.jpg -profile source.icc target.jpg', $ret );
I did not use -profile before because I thought -profile converts the image from one profile to another while -set profile just sets the profile. However it seems that at least of there is no previous profile in the file, then -profile also just adds it. On 6.6.6 The output file is identical to the one from -set profile.

Of course, the +profile "!icc,*" would have been nicer, because I would not have to export the profile first, but at least it works now!

Thanks for your help!

Cheers, Robert
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Convert: adding color profile does not work on Linux

Post by the-ninth »

Just one more question. I am trying to optimize this approach and reduce the number of calls I have to make.

Is there any way to do the the following two actions within one call to convert?

Code: Select all

convert source.jpg source.icc
convert source.jpg -strip -profile source.icc target.jpg
Thanks, Robert
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert: adding color profile does not work on Linux

Post by anthony »

version 6.3.5 is actually rather old. There has been a lot of updated and changes since that version. The preservation of color profiles by -thumbnail was one of those.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Convert: adding color profile does not work on Linux

Post by the-ninth »

@Anthony: I know ... but I already got a reply from my hosting provider that this is all they have and there won't be any upgrade anytime soon ... :(

The following at least combines the steps into one call to convert. I'd like to get rid of the temporary icc file as well, but it seems -profile only takes a physical file as input.

Code: Select all

convert source.jpg -write source.icc -strip -profile source.icc target.jpg
Cheers, Robert
Post Reply