用PHP设置imagick的密度参数 [英] set density parameter for imagick with php

查看:84
本文介绍了用PHP设置imagick的密度参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Imagick将pdf页面转换为png图像.

I want to convert a pdf page to a png image with Imagick.

我尝试使用PHP,但是图像质量很低.
当我尝试使用命令行时,结果是完美的.

I tried with PHP, but the image quality was very low.
When I tried with command line, the result was perfect.

PHP代码

$im = new imagick( __DIR__ . DIRECTORY_SEPARATOR.$PDFName.'['.$i.']' );  
$params = $im->identifyImage();
$width = $params['geometry']['width']*1;
$height = $params['geometry']['height']*1;
$im->setResolution(400,400);
$im->resizeImage($width ,$height, imagick::FILTER_SINC, 1, true);
$im->writeImage(__DIR__ . DIRECTORY_SEPARATOR.'pdf_pages\\'.$i.'.png'); 
$im->clear(); 
$im->destroy();

命令行代码

convert -density 400 a.pdf -resize 25% -a.png

PHP代码(第二次尝试)

$im = new imagick( __DIR__ . DIRECTORY_SEPARATOR.$PDFName.'['.$i.']' );  
$im->setOption('density','400x400');
$im->setOption('resize','25%');
$im->writeImage(__DIR__ . DIRECTORY_SEPARATOR.'pdf_pages\\'.$i.'.png'); 
$im->clear(); 
$im->destroy();

仍然是不好的结果.

我该怎么办?我想在我的PHP代码中使用density参数,但是如何?

What can I do? I want to use the density parameter in my PHP code, but how?

使用PHP输出

通过命令行输出

推荐答案

读取文件之前,您需要先设置分辨率 .

You need to set Resolution before you read the file.

$im = new imagick();
$im->setResolution(200,200);
$im->readImage(__DIR__ . DIRECTORY_SEPARATOR.$PDFName.'['.$i.']');

比,结果将是完美的.

希望这对某人有帮助.

Than, the result will be perfect.

Hope this help someone.

这篇关于用PHP设置imagick的密度参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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