Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GD and ICC profile #192

Open
golgote opened this issue Mar 3, 2020 · 1 comment
Open

GD and ICC profile #192

golgote opened this issue Mar 3, 2020 · 1 comment

Comments

@golgote
Copy link

golgote commented Mar 3, 2020

I have both GD and Imagick installed in my PHP. In my PDF, I use an image created with Imagick on which I add a CMYK profile for printing (CoatedFOGRA39.icc).

$img->setImageFormat('jpeg');
$img->getImageProfiles('*', null);
$icc_cmyk = file_get_contents('CoatedFOGRA39.icc');
$img->profileImage('icc', $icc_cmyk);
$img->transformImageColorspace(Imagick::COLORSPACE_CMYK);

$pdf->Image('@'.$img, $x, $y);

The resulting PDF generated with TCPDF has bad colors so the profile I give is not used and is replaced by something else or is simply removed.

I tracked this down to the Image() function. If GD is installed, it uses imagecreatetruecolor() and other functions that modify the original image and its data. If I comment out the block starting at if (($info === false) AND function_exists($gdfunction)) { then TCPDF correctly uses imagick and everything is fine because it finds the icc profile and keeps it.

So here are my suggestions to fix this:

  1. Change the order, call imagick before GD (imagick is better at everything so it should benefit everyone, but it is a potential BC break)
  2. Add a parameter to specify which image library to use. Most php image libraries do this these days. Keep this parameter empty by default. Example:
$pdf->setImageLibrary('imagick');

Any ideas?

@Gregoraz
Copy link

Gregoraz commented Jul 17, 2020

A little bit late, but:

        $iccCMYKPath = 'Coated_Fogra39L_VIGC_300.icc';
        $iccRGBPath = 'AdobeRGB1998.icc';
        $img->stripImage();
        $img->setImageColorspace(Imagick::COLORSPACE_SRGB);
        $icc_rgb = file_get_contents($iccRGBPath);
        $img->profileImage('icc', $icc_rgb);
        unset($icc_rgb);
        $icc_cmyk = file_get_contents($iccCMYKPath);
        $img->profileImage('icc', $icc_cmyk);
        $img->setImageColorspace(Imagick::COLORSPACE_CMYK);
        unset($icc_cmyk);
        $img->stripImage();

As far as I remember, I had to first profile image with rgb and then profile it with fogra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants