将 -density 开关与 -resize 的"不放大"标志一起使用不起作用




我正在研究图像转换服务的功能,我需要 缩放图像 -
如果请求的尺寸大于原始图像,则不应放大。
ImageMagick 支持这一点,
但是当我使用 -density 来提高转换后图像的质量(我从 pdf 转换为 png(时,"不放大"行为效果不佳。


例子:

Image attributes for /home/yzaslavs/Downloads/drawing.pdf
/home/yzaslavs/Downloads/drawing.pdf PBM 2271x1610 2271x1610+0+0 16-bit Bilevel Gray 457KB 0.000u 0:00.000
Starting conversions.............
convert /home/yzaslavs/Downloads/drawing.pdf -resize 5000x5000> out.png
out.png PNG 2271x1610 2271x1610+0+0 8-bit sRGB 383KB 0.000u 0:00.000
convert -resize 5000x5000> -background white -depth 8 -density 160x160 /home/yzaslavs/Downloads/drawing.pdf out.png
out.png PNG 5000x3545 5000x3545+0+0 8-bit sRGB 1.943MB 0.000u 0:00.000
-------
convert -background white -depth 8 -density 160x160 -resize 5000x5000> /home/yzaslavs/Downloads/drawing.pdf out.png
out.png PNG 5000x3545 5000x3545+0+0 8-bit sRGB 1.943MB 0.000u 0:00.000
-------
convert -background white /home/yzaslavs/Downloads/drawing.pdf -resize 5000x5000> out.pn
out.png PNG 2271x1610 2271x1610+0+0 8-bit sRGB 383KB 0.000u 0:00.000
-------
convert -background white -depth 8 /home/yzaslavs/Downloads/drawing.pdf -resize 5000x5000> out.png
out.png PNG 2271x1610 2271x1610+0+0 8-bit sRGB 383KB 0.000u 0:00.000
-------

提前感谢您的任何帮助

这是它与ImageMagickv7 一起工作的方式:

# Basic, default density is 72dpi
convert -depth 8 a.pdf -resize 5000x5000> info:
a.pdf PDF 595x842 595x842+0+0 8-bit sRGB 0.000u 0:00.000
# I specify density to match default and file comes out the same
convert -depth 8 -density 72 a.pdf -resize 5000x5000> info:
a.pdf PDF 595x842 595x842+0+0 8-bit sRGB 0.000u 0:00.000
# I increase the density 10% and image gets 10% bigger - fair enough!
convert -depth 8 -density 80 a.pdf -resize 5000x5000> info:
a.pdf PDF 661x935 661x935+0+0 8-bit sRGB 0.000u 0:00.000
# I double the density and the image doubles too - fair enough!
convert -depth 8 -density 144 a.pdf -resize 5000x5000> info:
a.pdf PDF 1191x1684 1191x1684+0+0 8-bit sRGB 0.000u 0:00.000
# I quadruple the density and the image quadruples too
convert -depth 8 -density 288 a.pdf -resize 5000x5000> info:
a.pdf PDF 2381x3368 2381x3368+0+0 8-bit sRGB 0.000u 0:00.000
# 8x density and image gets resized now too
convert -depth 8 -density 576 a.pdf -resize 5000x5000> info:
a.pdf PDF 3535x5000 3535x5000+0+0 8-bit sRGB 2.700u 0:02.699
# Still bigger density and image still resized
convert -depth 8 -density 800 a.pdf -resize 5000x5000> info:
a.pdf PDF 3535x5000 3535x5000+0+0 8-bit sRGB 3.890u 0:03.890

最新更新