PHP Imagick PDF Text Aliases

I am having problems converting PDFs to JPEGs using Imagick in PHP. After a lot of research, I can convert CMYK pdf to RGB jpg without weird color conversion ... but now, my last question: the text is completely anti-aliased! The text from the original PDF file is not vectorized.

Example:
Aliased text with pdf conversion

Here is the code:

$imagick = new Imagick();

$imagick->setResolution(150,150);
$imagick->readImage('file.pdf');

//CMYK PROFILE
$icc = file_get_contents('USWebCoatedSWOP.icc'); 
$imagick->profileImage('icc', $icc); 
$imagick->setImageColorspace(imagick::COLORSPACE_CMYK); 

//RGB PROFILE
$icc = file_get_contents('sRGB_IEC61966-2-1_no_black_scaling.icc'); 
$imagick->profileImage('icc', $icc); 
$imagick->setImageColorspace(imagick::COLORSPACE_RGB); 

$imagick->setImageFormat( "jpg" );
$imagick->setImageCompression(imagick::COMPRESSION_JPEG); 
$imagick->setImageCompressionQuality(90); 

header( "Content-Type: image/jpeg" );
echo $imagick;

      

0


source to share


2 answers


Image Magick uses Ghostscript to actually render PDFs, and I think you are using a version of Ghostscript with a bug in it that is causing the text to not be anti-aliased correctly.

I checked the code you provided as well as calling Ghostscript directly with the command.



gs -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=1 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r150  -sOutputFile=foo-%d.png flyer.pdf

      

By default, my Centos folder is using Ghostscript version 8.70 which shows the problem you see both when calling Imagick and in the gs command above. Downloading version 9.14 from here allows the text to be flattened correctly when using the command line and probably when invoked through Imagick.

+1


source


This is rather not an anti-aliasing problem.

Bump up the resolution to 400 and see what happens.



$imagick->setResolution(400,400);

      

0


source







All Articles