ImageMagick将PDF转换为低分辨率JPG文件 [英] ImageMagick Convert PDF to low resolution JPG file

查看:609
本文介绍了ImageMagick将PDF转换为低分辨率JPG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用ImageMagick在CodeIgniter上将PDF转换为JPG图像,但是生成的图像质量较低,并且由于某种原因总是具有黑色背景(而PDF不是)。

I have been trying to convert PDF to JPG images using ImageMagick on CodeIgniter, but the produced image is in low quality and always having black background for some reason (while PDF isn't).

我使用的代码

public function converter($pdf){
    $this->load->library('image_lib');

    $config = array(
        'image_library' => 'imagemagick',
        'library_path' => '/usr/bin/convert',
        'source_image' => "./pdf/".$pdf,
        'new_image' => "./images/a.jpg",
        'maintain_ratio' => true,
        'width' => 980,
        'quality' => '90%',
       );

       $this->image_lib->initialize( $config );

       if ( $this->image_lib->resize( ) ) {
        $this->image_lib->clear( );
       }
}

任何人都知道什么似乎是错误的这里?

Anybody have any idea about what does seem to be wrong here?

推荐答案

你需要两个CodeIgniter可能不支持的东西,所以你必须直接使用ImageMagick。

You need two things that CodeIgniter probably doesn't support, so you have to use ImageMagick directly.

首先,您必须设置PDF的分辨率以获得高质量的结果。在ImageMagick命令行上,可以使用 -density 选项来完成。使用PHP imagick,请使用 setResolution

First, you have to set the resolution of the PDF for a high-quality result. On the ImageMagick command line, this can be done with the -density option. With PHP imagick, use setResolution.

要摆脱黑色背景,您必须首先在白色背景上展平PDF。在命令行上,使用选项 -background white -flatten 。使用PHP imagick, setImageBackgroundColor flattenImages 应该可以正常工作。

To get rid of the black background, you have to flatten the PDF on a white background first. On the command line, use the options -background white -flatten. With PHP imagick, setImageBackgroundColor and flattenImages should work.

这篇关于ImageMagick将PDF转换为低分辨率JPG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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