Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMYK images turn negative with TCPDF

I have a problem using TCPDF to generate PDF images containing a CMYK PNG file.

The system allows the user to upload photos, which can be JPG, GIF or PNG. ImageMagick converts these images into CMYK from RGB where necessary. The image is then uploaded to the fileserver (Amazon S3).

When presented, the image is simply displayed on the screen in HTML on the "preview" page, and clicking a button generates the PDF.

The PDF is the point where the image goes negative (colours invert). From what I can tell, the image remains as expected until the point where TCPDF inserts the image into the document:

$tcpdf->Image($path_to_image, 0, 3.5, '42', '22', $file_extension, '', '', false, 300, '', false, false, 0, false, false, false);

enter image description here----> enter image description here

The file type is PNG, extension is png. Colour profile is CMYK. When opened in the browser, the image looks fine.

I also have not been able to replicate this on my local development environment, it only seems to occur on the live site which makes it even more difficult to replicate. This only seems to occur with PNG files.

The OP of this article passes over this issue in one of his ranting posts, but doesn't seem to resolve it.

Has anyone encountered this issue and worked out how to resolve it? I guess it's happening somewhere in the TCPDF (v5.9.103) class as the source file is fine.

like image 612
scrowler Avatar asked May 19 '14 01:05

scrowler


1 Answers

Well, unless Wikipedia is misinformed, there is not such thing as a CMYK png.

Here is Wikipedia extract:

PNG was designed for transferring images on the Internet, not for professional-quality print graphics, and therefore does not support non-RGB color spaces such as CMYK.

My guess is that browsers are not concerned with the color profile of the png, they'll always "see" it a RGB. I presume you set TCPDF to output a PDF in CMYK, and since .png files do not support CMYK...

Have you tried to convert it to .tiff (assuming you need to preserve alpha channels), and then to CMYK with Imagemagick, before passing it to TCPDF?

like image 81
Christian Bonato Avatar answered Sep 30 '22 09:09

Christian Bonato