繁体   English   中英

ImageMagick Pdf 转 JPG 质量差

[英]ImageMagick Pdf to JPG bad quality

我无法通过使用 ImageMagick 将 PDF 转换为图像来获得良好的色彩质量。

 MagickReadSettings settings = new MagickReadSettings();
        settings.Verbose = true;
        settings.Density = new Density(600, 600);

        MagickImageCollection images = new MagickImageCollection();
        images.Read("C:\\" + Path.GetFileName(fileUrl));
        List <string> files = new List<string>();
        for (var x = 0; x < images.Count; x++)
        {
            images[x].Quality = 100;
            images[x].BitDepth(24);
            images[x].Contrast(true);
            images[x].Resize(3675, 2400);
            images[x].Write("C:\\websites\\FlyerEditor2\\FlyerEditor\\src\\assets\\" + Path.GetFileNameWithoutExtension(fileUrl) + "-" + (x + 1) + ".jpeg");
            files.Add("assets/" + Path.GetFileNameWithoutExtension(fileUrl) + "-" + (x + 1) + ".jpeg");
        }

从 pdf 裁剪的屏幕截图

jpg 来自 pdf 使用 imageMagick

如果使用python3,你可以尝试使用魔杖。

在终端:

brew install imagemagick@6
pip install wand

在 python 中:

from wand.image import Image
pdf_file = '.../example/a.pdf'

def convert_pdf_to_jpg(file_name, pic_file, resolution=120):
    with Image(filename=file_name, resolution=resolution) as img:
        print('pages = ', len(img.sequence))
        with img.convert('jpeg') as converted:
            converted.save(filename=pic_file)

我发现 imagemagick 在 Linux 和 Windows 之间对色彩空间的转换处理存在重大差异。

使用命令

convert -density 300 -colorspace RGB my.pdf my.jpg
convert -density 300 -colorspace sRGB my.pdf my.jpg

在 Linux 上, -colorspace sRGB-colorspace RGB都生成了图像,其中对比度和调色板是原始图像的主要转移,对比度增加了,colors 与原始图像相差甚远。

在 Windows 上, -colorspace sRGB-colorspace RGB都可以接受,如果不完美的话。

好的,这个问题与 imageMagick 无关。 这是一个简单的彩色托盘问题。 将 pdf 转换为 jpeg 默认使用 cmyk,而 web 标准是 RGB

暂无
暂无

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

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