使用PHP和ImageMagick将PDF转换为高质量JPG [英] Convert PDF to high quality JPG using PHP and ImageMagick

查看:171
本文介绍了使用PHP和ImageMagick将PDF转换为高质量JPG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在把头发拔掉.

我有一个300 DPI PDF,我想将其转换为2550x3300的300 DPI JPG.有人告诉我ImageMagick可以做到这一点,所以我让ImageMagick可以工作,但是它只返回大小约为原始PDF大小1/5的JPG.

I have a 300 DPI PDF that I want to turn into a 300 DPI JPG that's 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.

这不是源图像-我已经用几个高质量的PDF做到了,它们都有相同的问题.

It's not the source image--I've done it with several high quality PDFs and they all have the same problem.

在寻找StackOverflow的想法后,这就是我想使用的方法:

After scouring StackOverflow for ideas, this is what I came up with to use:

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

但是它仍然不起作用.

我也尝试过使用$ img-> resizeImage()来调整JPG的大小,但是如果尺寸合适,它的质量就会很差.

I also have tried using $img->resizeImage() to resize the JPG, but then it comes out at really bad quality, if the right size.

完全被困住了.感谢您的帮助!

Totally stumped. Appreciate your help!

推荐答案

在读取图像之前,您需要设置分辨率.请

You need to set the resolution before reading the image in. Please see this comment on the manual - see if that will work.

这篇关于使用PHP和ImageMagick将PDF转换为高质量JPG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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