尽管设置了密度和调整大小选项,ImageMagick 仍将 PDF 转换为小图像

发布于 2025-01-15 23:56:25 字数 1386 浏览 1 评论 0原文

我正在使用 ImageMagick 将以下 PDF 转换为 PNG 文件: 来自 IMSLP 的 PDF (永久链接

在 PDF 查看器中它看起来不错(尽管它需要相当多的缩放) :

带有乐谱的 PDF 文件看起来不错

但使用

convert "file.pdf" "/tmp/file.png"

生成的图像进行转换时分辨率极低:

小图片< /a>

添加密度时并调整信息大小,我得到了更大的图像,但仍然不是 PDF 中存储的原始分辨率(当然不是 300 DPI)

convert -density "300" -resize "3000x3000>" "file.pdf" "/tmp/file.png"

图片仍然太小

使用 Poppler-Utils 时pdfimages,我得到了适当的图像:

正确缩放乐谱图像

我的问题是:有没有办法告诉 ImageMagick 以“正确”分辨率提取图像(如存储在 PDF 中 文档)?换句话说,忽略正确查看 PDF 所需的缩放,从而提取正确的图像分辨率?

我在 Alpine Linux docker 镜像中使用 ImageMagick 7.1.0.16 和 Ghostscript 9.55.0。

I'm using ImageMagick to convert the following PDF to an PNG file: PDF from IMSLP (Permalink)

In a PDF viewer it looks nice (even though it needs quite a bit of zooming):

PDF file with music scores that looks OK

but when converting with

convert "file.pdf" "/tmp/file.png"

the produced image gets an extremely low resolution:

tiny image

when adding density and resize information, I get somewhat bigger images, but still not the original resolution that is stored within the PDF (certainly not 300 DPI)

convert -density "300" -resize "3000x3000>" "file.pdf" "/tmp/file.png"

still too small image

When using Poppler-Utils' pdfimages, I'm getting the appropriate image:

Properly scaled image of music scores

My question is: Is there any way to tell ImageMagick to extract the images in the "correct" resolution (as is stored in the PDF document)? In other words, ignore the zoom that is necessary to view the PDF properly, thus extracting the correct image resolution?

I'm using ImageMagick 7.1.0.16 with Ghostscript 9.55.0 inside an Alpine Linux docker image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱要勇敢去追 2025-01-22 23:56:25

这是非常不寻常的结构,它经历了许多更改,但我们可以猜测某些页面可能已转换为 300 dpi 或 600 dpi,因为它们都以大致相同的尺寸呈现。

请注意,图形 dpi 是主观的,它不是 PDF 中使用的值,而是与图形工作 dpi 相关的 72 点单位的默认像素。图像的分辨率可能为 75 dpi,但以每 72 点 300 像素的形式存储。

第一个分析表示图像为

  • image-0028 = 714 X 900 点,名义上 600 dpi
  • image-0002 = 726 X 900 点,名义上 600 dpi
  • image-0005 = 674 x 900 点,名义上 600 dpi
  • image-0008 = 674 x 900 点,名义上 600 dpi
  • 图像-0011 = 674 x 900 点,名义上 600 dpi
  • image-0014 = 674 x 900 点,名义上 600 dpi

,但所有图像都已被下采样到各种尺寸,大约为 600 dpi。 1.2" x 1.5" 因此可能有一个合理的源尺寸来匹配所有这些减少
9.6 英寸 x 12 英寸,经过一些裁剪。

因此,要获得最接近的原始质量提取页面@ 600 dpi(无损png最好保留那些有损jpeg缺陷),

然后将它们重新转换为75 dpi应该会给你最接近的低质量输入。

Very unusual structure you have there its been through many changes but we can guess some pages may have been converted to 300 dpi or 600 dpi since they all render at roughly the same size.

Note that graphics dpi is subjective it is not that value that's used inside a PDF it is the the pixels per default of 72 point units that relate to a graphics working dpi. the image may have been 75 dpi but stored at 300 pixels per 72 points.

1st Analysis says images are

  • image-0028 = 714 X 900 dots nominally 600 dpi
  • image-0002 = 726 X 900 dots nominally 600 dpi
  • image-0005 = 674 x 900 dots nominally 600 dpi
  • image-0008 = 674 x 900 dots nominally 600 dpi
  • image-0011 = 674 x 900 dots nominally 600 dpi
  • image-0014 = 674 x 900 dots nominally 600 dpi

but all have been down-sampled to various sizes approx. 1.2" x 1.5" so a sensible source size to match all those reductions is possibly
9.6" x 12" with some cropping.

Thus to get the nearest original quality extract pages @ 600 dpi (lossless png would be best to keep those lossy jpeg flaws)

Then reconvert them to 75 dpi should give you the closest to the poor quality inputs.

比忠 2025-01-22 23:56:25

您需要将密度增加得更大,并在读取 Imagemagick 中的输入后调整大小。

这将是 5800 × 7200 像素:

convert -density 4800 IMSLP358086-PMLP578359-Ehr_OP_20_5.pdf[1] x.png

在此处输入图像描述

这将为 2417 × 3000 像素:

convert -density 4800 IMSLP358086-PMLP578359-Ehr_OP_20_5.pdf[1] -resize "3000x3000>" y.png

在此处输入图像描述

You need to increase your density much larger and put your resize after reading the input in Imagemagick.

This will be 5800 × 7200 pixels:

convert -density 4800 IMSLP358086-PMLP578359-Ehr_OP_20_5.pdf[1] x.png

enter image description here

This will be 2417 × 3000 pixels:

convert -density 4800 IMSLP358086-PMLP578359-Ehr_OP_20_5.pdf[1] -resize "3000x3000>" y.png

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文