CMYK images become negative with TCPDF

I have a problem using TCPDF to create 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 to CMYK from RGB, where necessary. The image is then uploaded to the file server (Amazon S3).

When presented, the image is simply displayed on the screen in HTML on the Preview page, and clicking the button creates a PDF file.

PDF is the point at which the image becomes negative (color inversion). From what I can tell, the image remains as expected until the moment when 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

File type is PNG, the extension is png . Color profile - CMYK. When opened in a browser, the image looks normal.

I also could not reproduce this in my local development environment, it only seems to be on a real site, which makes it even more difficult to replicate. This seems to only happen with PNG files.

OP this article conveys this issue in one of his ranting posts, but does not seem to resolve it.

Has anyone encountered this problem and figured out how to solve it? I assume this happens somewhere in the TCPDF class (v5.9.103), since the source file is fine.

+7
php pdf pdf-generation tcpdf cmyk
source share
3 answers

Well, if Wikipedia is not misinformed, there is no such thing as CMYK png.

Here is an excerpt from Wikipedia:

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

I assume that browsers are not associated with the png color profile, they will always “see” its RGB. I assume that you install TCPDF to output the PDF file to CMYK, and since .png files do not support CMYK ...

Have you tried converting it to .tiff (assuming you need to save alpha channels) and then to CMYK using Imagemagick before transferring it to TCPDF?

+7
source share

I don't know anything about TCPDF, and I have not tried CMYK PNG files yet.

But when I added CMYK JPEG file support to PDFsharp, I had to add the /DECODE with the value [1 0 1 0 1 0 1 0] for JPEG images with the /DeviceCMYK color space so that they display correctly using Adobe Reader.

I assume that CMYK PNG files need the same parameter that should display correctly (and not inverted).

The byte value of 255 is very bright with RGB colors and very dark with CMYK colors. Adobe Reader seems to need a hint to handle this correctly. RGB is additive, CMYK is subtractive.

The Adobe PDF Reference writes about DeviceCMYK color space:

Please note that the meaning of these numbers does not match the color value of the RGB component.

+3
source share

.png cannot use the CMYK color profile using .jpg . The fastest fix

 <?php $file = "myimage.png"; $image = imagecreatefrompng($file); $bg = imagecreatetruecolor(imagesx($image), imagesy($image)); imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255)); imagealphablending($bg, TRUE); imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image)); imagedestroy($image); header('Content-Type: image/jpeg'); $quality = 50; imagejpeg($bg); imagedestroy($bg); ?> 
-one
source share

All Articles