2017-08-16 32 views
0


我上的圖像轉換服務的功能工作,我需要 級的圖像 -
如果請求的尺寸更大原始圖像,它不應該enrlage。
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 
------- 

預先感謝您的任何幫助

+0

對於PNG,-density不影響調整。它只在打印時設置尺寸。它確實爲柵格化PDF的初始大小設置了像素尺寸。在閱讀PDF之後,應始終出現-resize,並且在閱讀PDF之前應該出現-density。如果您使用更大的密度,您將獲得更好的質量,而不是更大的尺寸。但是,調整大小將始終按您指定的大小調整大小。如果您希望它不調整大小,如果物種的尺寸WxH大於圖像,則使用-resize WxH \ <。請參閱http://www.imagemagick.org/script/command-line-processing.php#geometry – fmw42

+0

我知道密度是多少,事實上它與調整大小無關。提供\>手段 - 如果需要超過原始圖像屬性,請勿登錄。當你指定-density時,這不起作用。 再次看看我發佈的示例,它很好地展示了它。 –

+0

如果由標識提供的原始尺寸是例如500x500 - 並且我要求1000x1000,我不希望它被放大。這一切都出現在我上面的例子中 - 這些都是真實的執行結果。 –

回答

1

這是它如何與ImageMagick的 V7工作:

# 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 
+0

嗨,感謝您與您的示例運行運行。 爲什麼密度在「不放大」的情況下會影響調整大小? 無法形象magick保持密度增加相同的尺寸?你是如何獲得實驗的默認密度的?我願意爲我的默認密度。 –

+0

我搜索了一下,發現這個 - identify -format「%w x%h%x x%y」image.jpg 我將盡快更新。 謝謝! –

+0

識別-format 「%WX%H%XX%Y」 drawing.pdf 1684 X 2384 72 X 72
轉換-depth 8 -density 160 drawing.pdf [0] drawing.png
識別drawing.png
drawing.png PNG 3742x5298 3742x5298 + 0 + 0 8位sRGB 1.36MB 0.000u 0:00.000 –