[英]Convert PDF to high quality JPG using PHP and ImageMagick
I'm tearing my hair out. 我正在撕扯我的头发。
I have a 300 DPI PDF that I want to turn into a 300 DPI JPG that's 2550x3300. 我有一个300 DPI PDF,我想把它变成300 DPI JPG,即2550x3300。 I am told ImageMagick can do this, so I get ImageMagick to work, but it only returns a JPG that is sized about 1/5 the original PDF size.
我被告知ImageMagick可以这样做,所以我让ImageMagick工作,但它只返回一个大小约为原始PDF大小1/5的JPG。
It's not the source image--I've done it with several high quality PDFs and they all have the same problem. 它不是源图像 - 我使用了几个高质量的PDF来完成它们,它们都有同样的问题。
After scouring StackOverflow for ideas, this is what I came up with to use: 在为StackOverflow寻找创意之后,这就是我想出来的用法:
$im = new imagick($srcimg);
$im->setImageResolution(2550,3300);
$im->setImageFormat('jpeg');
$im->setImageCompression(imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(100);
$im->writeImage($targetimg);
$im->clear();
$im->destroy();
But it still doesn't work. 但它仍然无效。
I also have tried using $img->resizeImage() to resize the JPG, but then it comes out at really bad quality, if the right size. 我也尝试过使用$ img-> resizeImage()来调整JPG的大小,但如果尺寸合适,那么它的质量非常差。
Totally stumped. 完全难倒。 Appreciate your help!
感谢您的帮助!
您需要在读取图像之前设置分辨率。请参阅本手册中的注释 - 看看是否有效。
This would be the correct way, the quality will improve. 这将是正确的方式,质量将提高。
$im = new imagick();
$im->setResolution(300, 300);
$im->readImage($srcimg);
$im->setImageFormat('jpeg');
$im->setImageCompression(imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(100);
$im->writeImage($targetimg);
$im->clear();
$im->destroy();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.