PHP Imagick PDF转换文本别名 [英] PHP Imagick PDF conversion Text aliasing

查看:119
本文介绍了PHP Imagick PDF转换文本别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Imagick在PHP中将PDF文件转换为JPEG时遇到了一些麻烦. 经过大量研究,我能够将CMYK pdf转换为RGB jpg,而无需进行怪异的颜色转换……但现在,我的最后一个问题是:文本完全是别名!原始PDF文件中的文本未矢量化.

I'm having some troubles converting PDF files to JPEG with Imagick in PHP. After a lot of research, i'm able to convert CMYK pdf to RGB jpg without weird color conversion… but now, my last issue : the text is completely aliased ! The text from the original PDF file is not vectorized.

一个例子:
带有pdf转换的别名

An example :

这是代码:

$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;

推荐答案

Image Magick使用Ghostscript实际渲染PDF,我认为您使用的Ghostscript版本具有

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

我测试了您提供的代码,并使用命令直接调用了Ghostscript.

I tested the code you provided, as well as with a direct invocation of Ghostscript 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

默认情况下,我的Centos盒使用的是Ghostscript版本8.70,该版本显示了您从Imagick和上述gs命令调用时遇到的问题.从此处下载版本9.14可使使用命令行时文本正确消除锯齿,并且可能会通过Imagick调用.

By default, my Centos box was using Ghostscript version 8.70 which shows the issue you're seeing, both when invoked from Imagick and from the gs command above. Downloading version 9.14 from here makes the text be anti-aliased correctly when using the command-line, and probably would when invoked via Imagick.

这篇关于PHP Imagick PDF转换文本别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆