简体   繁体   English

使用PHP和ImageMagick将PDF转换为JPEG时的低分辨率测试

[英]Low resolution test when convert PDF to JPEG with PHP and ImageMagick

I have use this code to convert PDF file to JPEG images 我已使用此代码将PDF文件转换为JPEG图像

$im = new Imagick();
$im->setResolution(90,90);
$im->readImage($pdf_file);
$im->setImageFormat('jpeg');
$im->writeImages($save_to,false);
$im->clear(); 
$im->destroy();

and it work but I have a problem that when there is a text with white background it will not be clear but I don't have this problem when ever I have colored BG. 它可以正常工作,但是我有一个问题,当有白色背景的文字时,不清楚,但是当我给BG上色时,我就没有这个问题。

this image will make every thing clear 此图像将使一切变得清晰 在此处输入图片说明

JPEG compression generates such artefacts on edges where there is big color differences (such as between your black text and your white background). JPEG压缩会在颜色差异较大的边缘(例如黑色文本和白色背景之间)生成此类伪像。 Try to to push up the compression quality or use another image format for images containing text (such as png) 尝试提高压缩质量或对包含文本(例如png)的图像使用其他图像格式

Add this functions: 添加此功能:

$im = new Imagick();
$im->setResolution(90,90);

if ($width < 300) $im->sharpenImage(4, 1);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100); // or some alse 

$im->readImage($pdf_file);
$im->setImageFormat('jpeg');
$im->writeImages($save_to,false);
$im->clear(); 
$im->destroy();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM