1

I'm working on a project where I've had to learn about color profiles a bit, still very much a novice. This code doesn't seem to be adding the icc profile:

$im = new Imagick;
$im->readImage('input.tif');

print_r($im->getImageProfiles('*', false));

$im->stripImage();
$im->profileImage('icc', file_get_contents('myprofile.icc'));

print_r($im->getImageProfiles('*', false));

Result:

Array
(
    [0] => 8bim
    [1] => icc
    [2] => xmp
)
Array
(
)

If I change the argument icc to any other string it appears in the output, but the file size doesn't change (not certain if it would).

$im->profileImage('testWhatever', file_get_contents('myprofile.icc'));

This shows testWhatever in the second print_r() output.

What could be the issue and how can I debug this? I've read nearly every post here about this topic, I'm happy to provide more information.

Debug notes, hopefully something here is useful:

  • Version: ImageMagick 7.0.7-11 Q16 i686 2017-11-12
  • PHP version 5.6.4
  • Tiff file is CMYK

Output of convert -list configure

Path: /usr/local/lib/ImageMagick-7.0.7//config-Q16HDRI/configure.xml

Name           Value
-------------------------------------------------------------------------------
CC             gcc -std=gnu99 -std=gnu99
CFLAGS         -I/usr/include/libxml2   -I/usr/include/libpng12    -pthread -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12   -I/usr/include/freetype2        -fopenmp -g -O2 -Wall -mtune=core2 -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16
CODER_PATH     /usr/local/lib/ImageMagick-7.0.7/modules-Q16HDRI/coders
CONFIGURE      ./configure
CONFIGURE_PATH /usr/local/etc/ImageMagick-7/
COPYRIGHT      Copyright (C) 1999-2017 ImageMagick Studio LLC
CPPFLAGS       -I/usr/local/include/ImageMagick-7
CXX            g++
CXXFLAGS       -g -O2 -pthread
DEFS           -DHAVE_CONFIG_H
DELEGATES      bzlib mpeg fontconfig freetype jng jpeg pango png ps tiff x xml zlib
DISTCHECK_CONFIG_FLAGS  --disable-deprecated  --with-quantum-depth=16  --with-jemalloc=no  --with-umem=no  --with-autotrace=no  --with-gslib=no  --with-fontpath=  --with-rsvg=no  --with-perl=no
DOCUMENTATION_PATH /usr/local/share/doc/ImageMagick-7
EXEC-PREFIX    /usr/local
EXECUTABLE_PATH /usr/local/bin
FEATURES       DPC HDRI Cipher OpenMP
FILTER_PATH    /usr/local/lib/ImageMagick-7.0.7/modules-Q16HDRI/filters
GIT_REVISION   12832
HOST           i686-pc-linux-gnu
INCLUDE_PATH   /usr/local/include/ImageMagick-7
LDFLAGS        -L/usr/local/lib
LIB_VERSION    0x707
LIB_VERSION_NUMBER 7,0,7,11
LIBRARY_PATH   /usr/local/lib/ImageMagick-7.0.7
LIBS              -ltiff -lfreetype    -ljpeg   -lpng12        -lfontconfig      -lXext -lXt   -lSM -lICE -lX11   -lbz2   -pthread -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0     -lxml2    -lz    -lm -lgomp
NAME           ImageMagick
PCFLAGS        -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16
PREFIX         /usr/local
QuantumDepth   16
RELEASE_DATE   2017-11-21
SHARE_PATH     /usr/local/share/ImageMagick-7
SHAREARCH_PATH /usr/local/lib/ImageMagick-7.0.7/config-Q16HDRI
TARGET_CPU     i686
TARGET_OS      linux-gnu
TARGET_VENDOR  pc
VERSION        7.0.7
WEBSITE        http://www.imagemagick.org

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       OpenMP
NAME           ImageMagick
QuantumDepth   16
Community
  • 1
  • 1
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • could sound like a silly question here, but anything from error reporting? – Funk Forty Niner Nov 21 '17 at 13:41
  • Nothing, and the call returns `true` when adding the profile. – Wesley Murch Nov 21 '17 at 13:42
  • I have to pick my (very old) graphic art experience here *lol* - but is the TIFF file actually 8 bit and contains channels? What is the file's profile? If the file's grayscale, or RGB or CMYK, then maybe that could be playing a role here. Could you post what myprofile.icc contains? What does `var_dump($im);` reveal? and MAC/Windows? other? could be the TIFF's version. – Funk Forty Niner Nov 21 '17 at 13:46
  • We suspect it might be related to the first comment on the manual page: http://php.net/manual/en/imagick.profileimage.php I'll leave this up in the meantime. *"If profileImage() seems to be doing nothing — and "inverted colors" during a CMYK > RGB conversion is a sign of this — check that ImageMagick has the lcms delegate available. If you don't see lcms in the list then Imagick won't do any color profile conversions, and won't give any warnings about this. In that case, install the Little CMS library and recompile ImageMagick."* – Wesley Murch Nov 21 '17 at 16:00
  • Ah... so what I said in my second comment might have held some truth to it then, correct? – Funk Forty Niner Nov 21 '17 at 16:22
  • Added some more details @Fred-ii- although I suspect this will become a tumbleweed. Thanks for your interest. – Wesley Murch Nov 24 '17 at 16:34

1 Answers1

1

Figured it out thanks to a comment on the profileImage manual page:

http://php.net/manual/en/imagick.profileimage.php

Solution: Install LCMS delegates and recompile ImageMagick, you may need to remove and reinstall the PHP extension as well.

If profileImage() seems to be doing nothing — and "inverted colors" during a CMYK > RGB conversion is a sign of this — check that ImageMagick has the lcms delegate available.

From a command prompt:

convert -list configure | grep DELEGATES

If you don't see lcms in the list then Imagick won't do any color profile conversions, and won't give any warnings about this. In that case, install the Little CMS library ( http://www.littlecms.com/ ) and recompile ImageMagick.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • I'm having the same issue. It shows lmcs is there, but profileImage still won't set the colour profile. I'm able to convert CMYK to RGB but the colour are a little off. Doesn't seem to be much documentation of this anywhere – Adam Collingburn Oct 29 '19 at 20:59
  • Did you find anything @AdamCollingburn? I'm having similar trouble, see https://stackoverflow.com/questions/62421778/why-would-converting-cmyk-image-to-srgb-for-display-on-web-work-locally-but-not, our production server isn't applying the profile, but my local linux server is. – Neek Jun 17 '20 at 05:51
  • @Neek Yeah I got it sorted - it was both LCMS + having to ensure a profile was added before the conversion. But if you're finding that prod is the issue, you'll need to uninstall imagick and imagemagick and then build/install imagemagick again and then install imagick with pecl. It's a pain, I know, but just bite the bullet because it solved a lot of my problems – Adam Collingburn Jun 18 '20 at 23:18
  • Thanks @AdamCollingburn .. I think I'm lucky, lcms seems to be included in the delegates for the packaged version these days (I seem to recall a few years ago this was not the case). I seem to have identified a regression in ImageMagick itself but I'm no expert in this, see https://github.com/ImageMagick/ImageMagick6/issues/83#issuecomment-646402346 .. I can get it to 'work' using the older version on command line, but the PHP bindings have never worked for me that I can remember. – Neek Jun 19 '20 at 03:11