Help wanted: test PDF with 'bad' transparency
It seems that some PDFs have transparent areas that render incorrectly under certain versions of ghostscript. eg. see https://github.com/Imagick/imagick/issues/389
I would like to be able to have a test image that I can distribute as part of a testsuite. Obviously I can't do that with the PDF in that bug report as it is copyrighted material.
Please could someone with access to PDF authoring software, find a way of making a PDF that shows this problem.
An example version of Ghostscript that shows this problem is Ghostscript 9.26 and the conversion can be tested directly through Ghostscript with this command:
./gs -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=gs_output.png' '-fTestImage.pdf'
Please use this image as the background of the PDF: https://github.com/Imagick/imagick/blob/test_image/tests/images/Robin.jpg as it's an image I own the copyright to and so can distribute without getting sued...
I suspect that the issue may be caused by using a CMYK colour as the background colour, or some other slightly edgecase technique.
I am not sure that this actually solves this issue, however, I had similar issue with PDF(and .ai/.eps) with transparent background. While searching, I was multiple times found exactly this issue, so this comment might help somebody in the Future.
My issue was that when I try to read PDF, I always get black background instead of "transparent".
To make this worse, it was working correctly on version 6.9, but stopped worked on 7.1 branch.
Solution was to actually specify target colorpsace before reading image.
Original Image: cmyk.pdf
Without colorspace specified.
With colorspace specified.
For example:
/*
* Original Image
*/
$img = new \Imagick();
$img->setColorspace(\Imagick::COLORSPACE_RGB); // This lines fixes issue. It MUST be before readImage
$img->readImage(__DIR__ . '/tests/cmyk.pdf');
$img->setImageFormat("png");
/**
* Let's add blue background so we can actually see that image has transparent background.
*/
$image2 = new \Imagick();
$image2->newImage($img->getImageWidth(), $img->getImageHeight(), 'blue');
$image2->compositeImage($img, \Imagick::COMPOSITE_DEFAULT, 0, 0);
$image2->setImageFormat("png");
header("Content-Type: image/png");
echo $image2->getImageBlob();
Hopefully this will help somebody. I had to actually spend around 20-30 hours on this issue.
If needed, you can use this test file for testsuite.