ImageMagick:PNG的无损最大压缩?

Posted

技术标签:

【中文标题】ImageMagick:PNG的无损最大压缩?【英文标题】:ImageMagick: Lossless max compression for PNG? 【发布时间】:2015-01-31 17:48:00 【问题描述】:

我希望在使用 ImageMagick 保存到无损 PNG 时实现最大程度的压缩。我正在批量转换许多 PSD。

我尝试了一些方法,但在我看来,生成的 PNG 图像不像原始图像那样清晰,虽然我的妻子看不到它。

这些是我正在使用的当前参数:

convert -depth 24 -define png:compression-filter=1 \ 
  -define png:compression-level=9 -define png:compression-strategy=2 

根据: http://www.imagemagick.org/script/command-line-options.php#define

还有http://www.w3.org/TR/PNG-Filters.html

这意味着:

压缩过滤器为 1(子) 最大压缩级别 9 压缩策略是 2 huffman_only(所以没有过滤,虽然这个压缩过滤器应该是无损的)

根据文档:“有效值为 0 到 4,表示默认、过滤、huffman_only、rle 和固定 ZLIB 压缩策略。如果您使用的是不支持 Z_RLE(1.2 之前)的旧 zlib。 0) 或 Z_FIXED(1.2.2.2 之前),值 3 和 4 将分别使用 zlib 默认策略。"

顺便说一句,我的图像是 960x720 像素。

(如果我使用默认压缩策略 0,我会得到大文件。可能是 9 的压缩过滤器和 0 的压缩策略产生较小尺寸的图像,但我仍然不确定它是否无损)。

问题:

    这是无损压缩吗?如果不是,错在哪里? 知道如何实现更好的无损压缩吗?

【问题讨论】:

你试过pngcrush吗?如果是这样,您是否将其结果与 ImageMagick 的结果进行了比较? 所有模式都是无损的,PNG 在设计上是无损的 您可以考虑使用其他几个 png 工具。见imagemagick.org/Usage/formats/#png_non-im。另请参阅imagemagick.org/script/command-line-options.php#quality 的 PNG 质量值 【参考方案1】:

如果只关心最终图片大小,可以试试下面的配置

/usr/local/Cellar/imagemagick/7.0.10-61/bin/convert -quality 60% -adaptive-resize 60% input.png output.png

结果图片大小如下

-rwxr-xr-x@ 1 admin  staff   2.4M Jul  3  2020 /Users/admin/Desktop/input.png*
-rw-r--r--  1 admin  staff   781K Feb  7 23:02 /Users/admin/Desktop/output.png

【讨论】:

【参考方案2】:

我玩了半天。我确实将图像大小调整为 360x240 像素。我得到了最好的结果:

 convert -depth 24 -define png:compression-filter=2 \
         -define png:compression-level=9 -define png:compression-strategy=1

【讨论】:

用 3.1Mb 的图像测试,它被减少到 2.6Mb。这是最好的和绝对最快的方法之一。我已经尝试过 optipng 和 pngcrush +1 由于某种原因,这实际上增加了我的图像大小:/ 这取决于图像的类型和大小,这是否可行。为了快速调整到 360x240px,我得到了最好的结果。如果您要调整单个图像的大小,pngcrush 或 optipng 肯定会为您找到最佳解决方案,但它会持续存在。如果您要调整数千张图片的大小,您可能会找到适合一张图片的方法,然后对其余图片执行相同的算法。 你在哪里给出文件名? 在命令的最后是源文件和目标文件【参考方案3】:

我得到的最佳压缩如下:

convert wallpsw.png -resize 1024x768 -quality 95 \
                    -depth 8 wallpsw-q95-r1024x768-d8.png

结果:

identify wallpsw*

 wallpsw.png PNG 1920x1080 1920x1080+0+0 16-bit DirectClass 4.63MB 0.000u 0:00.000
 wallpsw-q95-r1024x768-d8.png[1] PNG 1024x576 1024x576+0+0 8-bit DirectClass 854KB 0.000u 0:00.000

如果有人知道更好的方法,请告诉我。我找不到。

【讨论】:

你试过 convert -depth 24 -define png:compression-filter=2 -define png:compression-level=9 -define png:compression-strategy=1 InfectiousDesease1.psd[0] 测试。 png 这是命令:转换 mkj-by-xylomon-1920x1200.png -depth 24 -define png:compression-filter=2 -define png:compression-level=9 -define png:compression- strategy=1 InfectiousDesease1.psd[0] mkj-by-xylomon-1920x1200-***.png 这是控制台的输出:convert.im6:无法打开图像`InfectiousDesease1.psd':不存在el archivo o el Directorio @错误/blob.c/OpenBlob/2638. 大声笑而不是 `InfectiousDesease1.psd[0]' 使用你的文件名【参考方案4】:

deflate 压缩算法使用 65K 历史窗口。 PNG 压缩往往相当慢,因为该过程必须将压缩流中的字节序列与窗口中的字节序列进行比较。

您可以通过限制窗口的搜索来控制压缩的速度。您可能只在缓冲区的一半中搜索匹配项以加快处理速度(作为降低压缩率的风险)。

在 JPEG 中,需要在质量和大小之间进行权衡。在 PNG 压缩中,需要在速度和大小之间进行权衡。

无论如何,PNG 压缩过程始终是无损的。

【讨论】:

+1 用于强调 “PNG 压缩始终是无损的”“在压缩速度和最终大小之间进行权衡”.【参考方案5】:

我认为您已达到或超出 ImageMagick 文档的限制,并且建议您根据经验得出答案 - 或者如果您确实得到了明确的答案,您至少可以根据经验进行测试。

我无权访问您的图片,所以我自己生成了一张参考图片,如下所示。它包含一个易于压缩的纯色(红色)块、一个黑白渐变和一堆噪点,因此其中有一些东西可以让大多数类型的压缩感到高兴或不高兴。

为了测试您是否有无损压缩,我建议您将图像转换为PPM 格式 - 请参阅here。这不包含日期、时间或统计数据或任何内容,仅包含以极其简单的格式显示的纯图像数据和大小 - 从而可以比较像素值是否通过压缩发生了变化。

然后我编写了如下脚本,使用所有可能的过滤器、策略和级别来压缩参考图像,以查看文件大小以及它们是否遭受了任何损失,因此与参考图像 PPM 不同:

这是脚本:

#!/bin/bash
convert -depth 24 -size 200x200 xc:red gradient:black-white \( xc:white +noise random \) +append reference.png
convert reference.png reference.ppm
for f in 0..5; do
   for l in 0..9; do
      for s in 0..4; do
         outfile="out_$f_$l_$s.png"
         convert reference.png -define png:compression-filter=$f -define png:compression-level=$l -define png:compression-strategy=$s "$outfile"
         size=$(OSXFileSize "$outfile")
         echo filter:$f, level:$l, strategy:$s, size:$size
         convert "$outfile" "$outfile.ppm"
         diff "$outfile.ppm" reference.ppm
      done
   done
done

所有文件比较相同,因此我使用的任何参数似乎都没有任何压缩损失。尺寸如下:

filter:0, level:0, strategy:0, size:720796
filter:0, level:0, strategy:1, size:720796
filter:0, level:0, strategy:2, size:720801
filter:0, level:0, strategy:3, size:718136
filter:0, level:0, strategy:4, size:720796
filter:0, level:1, strategy:0, size:246377
filter:0, level:1, strategy:1, size:246377
filter:0, level:1, strategy:2, size:524864
filter:0, level:1, strategy:3, size:517549
filter:0, level:1, strategy:4, size:259348
filter:0, level:2, strategy:0, size:246377
filter:0, level:2, strategy:1, size:246377
filter:0, level:2, strategy:2, size:524864
filter:0, level:2, strategy:3, size:517549
filter:0, level:2, strategy:4, size:259348
filter:0, level:3, strategy:0, size:246377
filter:0, level:3, strategy:1, size:246377
filter:0, level:3, strategy:2, size:524864
filter:0, level:3, strategy:3, size:517549
filter:0, level:3, strategy:4, size:259348
filter:0, level:4, strategy:0, size:244894
filter:0, level:4, strategy:1, size:244859
filter:0, level:4, strategy:2, size:524864
filter:0, level:4, strategy:3, size:517549
filter:0, level:4, strategy:4, size:258039
filter:0, level:5, strategy:0, size:244916
filter:0, level:5, strategy:1, size:244881
filter:0, level:5, strategy:2, size:524864
filter:0, level:5, strategy:3, size:517549
filter:0, level:5, strategy:4, size:258064
filter:0, level:6, strategy:0, size:244916
filter:0, level:6, strategy:1, size:244881
filter:0, level:6, strategy:2, size:524864
filter:0, level:6, strategy:3, size:517549
filter:0, level:6, strategy:4, size:258064
filter:0, level:7, strategy:0, size:244916
filter:0, level:7, strategy:1, size:244881
filter:0, level:7, strategy:2, size:524864
filter:0, level:7, strategy:3, size:517549
filter:0, level:7, strategy:4, size:258064
filter:0, level:8, strategy:0, size:244433
filter:0, level:8, strategy:1, size:244405
filter:0, level:8, strategy:2, size:524864
filter:0, level:8, strategy:3, size:517549
filter:0, level:8, strategy:4, size:257674
filter:0, level:9, strategy:0, size:244433
filter:0, level:9, strategy:1, size:244405
filter:0, level:9, strategy:2, size:524864
filter:0, level:9, strategy:3, size:517549
filter:0, level:9, strategy:4, size:257674
filter:1, level:0, strategy:0, size:720796
filter:1, level:0, strategy:1, size:720796
filter:1, level:0, strategy:2, size:720801
filter:1, level:0, strategy:3, size:286904
filter:1, level:0, strategy:4, size:720796
filter:1, level:1, strategy:0, size:247643
filter:1, level:1, strategy:1, size:247643
filter:1, level:1, strategy:2, size:331829
filter:1, level:1, strategy:3, size:245708
filter:1, level:1, strategy:4, size:260505
filter:1, level:2, strategy:0, size:247375
filter:1, level:2, strategy:1, size:247375
filter:1, level:2, strategy:2, size:331829
filter:1, level:2, strategy:3, size:245708
filter:1, level:2, strategy:4, size:260452
filter:1, level:3, strategy:0, size:247375
filter:1, level:3, strategy:1, size:247375
filter:1, level:3, strategy:2, size:331829
filter:1, level:3, strategy:3, size:245708
filter:1, level:3, strategy:4, size:260452
filter:1, level:4, strategy:0, size:245515
filter:1, level:4, strategy:1, size:245489
filter:1, level:4, strategy:2, size:331829
filter:1, level:4, strategy:3, size:245708
filter:1, level:4, strategy:4, size:258810
filter:1, level:5, strategy:0, size:245544
filter:1, level:5, strategy:1, size:245519
filter:1, level:5, strategy:2, size:331829
filter:1, level:5, strategy:3, size:245708
filter:1, level:5, strategy:4, size:258835
filter:1, level:6, strategy:0, size:245597
filter:1, level:6, strategy:1, size:245570
filter:1, level:6, strategy:2, size:331829
filter:1, level:6, strategy:3, size:245708
filter:1, level:6, strategy:4, size:258885
filter:1, level:7, strategy:0, size:245597
filter:1, level:7, strategy:1, size:245570
filter:1, level:7, strategy:2, size:331829
filter:1, level:7, strategy:3, size:245708
filter:1, level:7, strategy:4, size:258885
filter:1, level:8, strategy:0, size:245251
filter:1, level:8, strategy:1, size:245230
filter:1, level:8, strategy:2, size:331829
filter:1, level:8, strategy:3, size:245708
filter:1, level:8, strategy:4, size:258587
filter:1, level:9, strategy:0, size:245267
filter:1, level:9, strategy:1, size:245254
filter:1, level:9, strategy:2, size:331829
filter:1, level:9, strategy:3, size:245708
filter:1, level:9, strategy:4, size:258589
filter:2, level:0, strategy:0, size:720796
filter:2, level:0, strategy:1, size:720796
filter:2, level:0, strategy:2, size:720801
filter:2, level:0, strategy:3, size:628470
filter:2, level:0, strategy:4, size:720796
filter:2, level:1, strategy:0, size:246114
filter:2, level:1, strategy:1, size:246114
filter:2, level:1, strategy:2, size:439545
filter:2, level:1, strategy:3, size:358177
filter:2, level:1, strategy:4, size:258999
filter:2, level:2, strategy:0, size:246114
filter:2, level:2, strategy:1, size:246114
filter:2, level:2, strategy:2, size:439545
filter:2, level:2, strategy:3, size:358177
filter:2, level:2, strategy:4, size:258999
filter:2, level:3, strategy:0, size:246114
filter:2, level:3, strategy:1, size:246114
filter:2, level:3, strategy:2, size:439545
filter:2, level:3, strategy:3, size:358177
filter:2, level:3, strategy:4, size:258999
filter:2, level:4, strategy:0, size:244701
filter:2, level:4, strategy:1, size:244679
filter:2, level:4, strategy:2, size:439545
filter:2, level:4, strategy:3, size:358177
filter:2, level:4, strategy:4, size:257722
filter:2, level:5, strategy:0, size:244721
filter:2, level:5, strategy:1, size:244700
filter:2, level:5, strategy:2, size:439545
filter:2, level:5, strategy:3, size:358177
filter:2, level:5, strategy:4, size:257744
filter:2, level:6, strategy:0, size:244727
filter:2, level:6, strategy:1, size:244704
filter:2, level:6, strategy:2, size:439545
filter:2, level:6, strategy:3, size:358177
filter:2, level:6, strategy:4, size:257744
filter:2, level:7, strategy:0, size:244727
filter:2, level:7, strategy:1, size:244704
filter:2, level:7, strategy:2, size:439545
filter:2, level:7, strategy:3, size:358177
filter:2, level:7, strategy:4, size:257744
filter:2, level:8, strategy:0, size:244340
filter:2, level:8, strategy:1, size:244322
filter:2, level:8, strategy:2, size:439545
filter:2, level:8, strategy:3, size:358177
filter:2, level:8, strategy:4, size:257436
filter:2, level:9, strategy:0, size:244155
filter:2, level:9, strategy:1, size:244130
filter:2, level:9, strategy:2, size:439545
filter:2, level:9, strategy:3, size:358177
filter:2, level:9, strategy:4, size:257298
filter:3, level:0, strategy:0, size:720796
filter:3, level:0, strategy:1, size:720796
filter:3, level:0, strategy:2, size:720801
filter:3, level:0, strategy:3, size:600694
filter:3, level:0, strategy:4, size:720796
filter:3, level:1, strategy:0, size:247741
filter:3, level:1, strategy:1, size:247741
filter:3, level:1, strategy:2, size:429487
filter:3, level:1, strategy:3, size:346943
filter:3, level:1, strategy:4, size:260468
filter:3, level:2, strategy:0, size:247711
filter:3, level:2, strategy:1, size:247711
filter:3, level:2, strategy:2, size:429487
filter:3, level:2, strategy:3, size:346943
filter:3, level:2, strategy:4, size:260444
filter:3, level:3, strategy:0, size:247463
filter:3, level:3, strategy:1, size:247463
filter:3, level:3, strategy:2, size:429487
filter:3, level:3, strategy:3, size:346943
filter:3, level:3, strategy:4, size:260331
filter:3, level:4, strategy:0, size:245681
filter:3, level:4, strategy:1, size:245659
filter:3, level:4, strategy:2, size:429487
filter:3, level:4, strategy:3, size:346943
filter:3, level:4, strategy:4, size:258797
filter:3, level:5, strategy:0, size:245685
filter:3, level:5, strategy:1, size:245663
filter:3, level:5, strategy:2, size:429487
filter:3, level:5, strategy:3, size:346943
filter:3, level:5, strategy:4, size:258796
filter:3, level:6, strategy:0, size:245686
filter:3, level:6, strategy:1, size:245665
filter:3, level:6, strategy:2, size:429487
filter:3, level:6, strategy:3, size:346943
filter:3, level:6, strategy:4, size:258796
filter:3, level:7, strategy:0, size:245686
filter:3, level:7, strategy:1, size:245665
filter:3, level:7, strategy:2, size:429487
filter:3, level:7, strategy:3, size:346943
filter:3, level:7, strategy:4, size:258796
filter:3, level:8, strategy:0, size:245474
filter:3, level:8, strategy:1, size:245458
filter:3, level:8, strategy:2, size:429487
filter:3, level:8, strategy:3, size:346943
filter:3, level:8, strategy:4, size:258628
filter:3, level:9, strategy:0, size:245508
filter:3, level:9, strategy:1, size:245491
filter:3, level:9, strategy:2, size:429487
filter:3, level:9, strategy:3, size:346943
filter:3, level:9, strategy:4, size:258639
filter:4, level:0, strategy:0, size:720796
filter:4, level:0, strategy:1, size:720796
filter:4, level:0, strategy:2, size:720801
filter:4, level:0, strategy:3, size:284043
filter:4, level:0, strategy:4, size:720796
filter:4, level:1, strategy:0, size:246892
filter:4, level:1, strategy:1, size:246892
filter:4, level:1, strategy:2, size:331489
filter:4, level:1, strategy:3, size:245305
filter:4, level:1, strategy:4, size:259428
filter:4, level:2, strategy:0, size:246299
filter:4, level:2, strategy:1, size:246299
filter:4, level:2, strategy:2, size:331489
filter:4, level:2, strategy:3, size:245305
filter:4, level:2, strategy:4, size:259021
filter:4, level:3, strategy:0, size:246316
filter:4, level:3, strategy:1, size:246316
filter:4, level:3, strategy:2, size:331489
filter:4, level:3, strategy:3, size:245305
filter:4, level:3, strategy:4, size:259026
filter:4, level:4, strategy:0, size:244335
filter:4, level:4, strategy:1, size:244259
filter:4, level:4, strategy:2, size:331489
filter:4, level:4, strategy:3, size:245305
filter:4, level:4, strategy:4, size:257491
filter:4, level:5, strategy:0, size:244343
filter:4, level:5, strategy:1, size:244260
filter:4, level:5, strategy:2, size:331489
filter:4, level:5, strategy:3, size:245305
filter:4, level:5, strategy:4, size:257494
filter:4, level:6, strategy:0, size:244350
filter:4, level:6, strategy:1, size:244262
filter:4, level:6, strategy:2, size:331489
filter:4, level:6, strategy:3, size:245305
filter:4, level:6, strategy:4, size:257500
filter:4, level:7, strategy:0, size:244350
filter:4, level:7, strategy:1, size:244262
filter:4, level:7, strategy:2, size:331489
filter:4, level:7, strategy:3, size:245305
filter:4, level:7, strategy:4, size:257500
filter:4, level:8, strategy:0, size:244282
filter:4, level:8, strategy:1, size:244251
filter:4, level:8, strategy:2, size:331489
filter:4, level:8, strategy:3, size:245305
filter:4, level:8, strategy:4, size:257461
filter:4, level:9, strategy:0, size:244321
filter:4, level:9, strategy:1, size:244284
filter:4, level:9, strategy:2, size:331489
filter:4, level:9, strategy:3, size:245305
filter:4, level:9, strategy:4, size:257473
filter:5, level:0, strategy:0, size:720796
filter:5, level:0, strategy:1, size:720796
filter:5, level:0, strategy:2, size:720801
filter:5, level:0, strategy:3, size:287526
filter:5, level:0, strategy:4, size:720796
filter:5, level:1, strategy:0, size:247117
filter:5, level:1, strategy:1, size:247117
filter:5, level:1, strategy:2, size:331910
filter:5, level:1, strategy:3, size:246241
filter:5, level:1, strategy:4, size:259811
filter:5, level:2, strategy:0, size:246903
filter:5, level:2, strategy:1, size:246903
filter:5, level:2, strategy:2, size:331910
filter:5, level:2, strategy:3, size:246241
filter:5, level:2, strategy:4, size:259757
filter:5, level:3, strategy:0, size:246976
filter:5, level:3, strategy:1, size:246976
filter:5, level:3, strategy:2, size:331910
filter:5, level:3, strategy:3, size:246241
filter:5, level:3, strategy:4, size:259742
filter:5, level:4, strategy:0, size:245005
filter:5, level:4, strategy:1, size:244969
filter:5, level:4, strategy:2, size:331910
filter:5, level:4, strategy:3, size:246241
filter:5, level:4, strategy:4, size:258135
filter:5, level:5, strategy:0, size:245025
filter:5, level:5, strategy:1, size:244985
filter:5, level:5, strategy:2, size:331910
filter:5, level:5, strategy:3, size:246241
filter:5, level:5, strategy:4, size:258149
filter:5, level:6, strategy:0, size:245056
filter:5, level:6, strategy:1, size:245009
filter:5, level:6, strategy:2, size:331910
filter:5, level:6, strategy:3, size:246241
filter:5, level:6, strategy:4, size:258176
filter:5, level:7, strategy:0, size:245056
filter:5, level:7, strategy:1, size:245009
filter:5, level:7, strategy:2, size:331910
filter:5, level:7, strategy:3, size:246241
filter:5, level:7, strategy:4, size:258176
filter:5, level:8, strategy:0, size:244838
filter:5, level:8, strategy:1, size:244841
filter:5, level:8, strategy:2, size:331910
filter:5, level:8, strategy:3, size:246241
filter:5, level:8, strategy:4, size:258009
filter:5, level:9, strategy:0, size:244857
filter:5, level:9, strategy:1, size:244857
filter:5, level:9, strategy:2, size:331910
filter:5, level:9, strategy:3, size:246241
filter:5, level:9, strategy:4, size:258009

显然,您的数字会有所不同,因为您的图像不同,因此您必须查看哪些对您的数据有效 - 但希望这将是一个起点。

请注意,如果我按大小对上述内容进行排序,我会得到:

filter:2, level:9, strategy:1, size:244127
filter:2, level:9, strategy:0, size:244156
filter:4, level:8, strategy:1, size:244251
filter:4, level:4, strategy:1, size:244258
filter:4, level:5, strategy:1, size:244260
filter:4, level:6, strategy:1, size:244262
filter:4, level:7, strategy:1, size:244262
filter:4, level:8, strategy:0, size:244283
filter:4, level:9, strategy:1, size:244285
filter:2, level:8, strategy:1, size:244319
filter:4, level:9, strategy:0, size:244321
filter:4, level:4, strategy:0, size:244333
filter:2, level:8, strategy:0, size:244341
filter:4, level:5, strategy:0, size:244341
filter:4, level:6, strategy:0, size:244350
filter:4, level:7, strategy:0, size:244350
filter:0, level:8, strategy:1, size:244408
filter:0, level:9, strategy:1, size:244408
filter:0, level:8, strategy:0, size:244442
filter:0, level:9, strategy:0, size:244442
filter:2, level:4, strategy:1, size:244677
filter:2, level:5, strategy:1, size:244699
filter:2, level:4, strategy:0, size:244701
filter:2, level:6, strategy:1, size:244704
filter:2, level:7, strategy:1, size:244704
filter:2, level:5, strategy:0, size:244723
filter:2, level:6, strategy:0, size:244729
filter:2, level:7, strategy:0, size:244729
filter:5, level:8, strategy:1, size:244813
filter:5, level:8, strategy:0, size:244822
filter:5, level:9, strategy:1, size:244840
filter:5, level:9, strategy:0, size:244853
filter:0, level:4, strategy:1, size:244860
filter:0, level:5, strategy:1, size:244885
filter:0, level:6, strategy:1, size:244885
filter:0, level:7, strategy:1, size:244885
filter:0, level:4, strategy:0, size:244897
filter:0, level:5, strategy:0, size:244922
filter:0, level:6, strategy:0, size:244922
filter:0, level:7, strategy:0, size:244922
filter:5, level:4, strategy:1, size:244940
filter:5, level:5, strategy:1, size:244956
filter:5, level:6, strategy:1, size:244980
filter:5, level:7, strategy:1, size:244980
filter:5, level:4, strategy:0, size:244982
filter:5, level:5, strategy:0, size:245000
filter:5, level:6, strategy:0, size:245030
filter:5, level:7, strategy:0, size:245030
filter:1, level:8, strategy:1, size:245243
filter:1, level:9, strategy:1, size:245245
filter:1, level:8, strategy:0, size:245267
filter:1, level:9, strategy:0, size:245270
filter:4, level:1, strategy:3, size:245307
filter:4, level:2, strategy:3, size:245307
filter:4, level:3, strategy:3, size:245307
filter:4, level:4, strategy:3, size:245307
filter:4, level:5, strategy:3, size:245307
filter:4, level:6, strategy:3, size:245307
filter:4, level:7, strategy:3, size:245307
filter:4, level:8, strategy:3, size:245307
filter:4, level:9, strategy:3, size:245307
filter:3, level:8, strategy:1, size:245460
filter:5, level:1, strategy:3, size:245469
filter:5, level:2, strategy:3, size:245469
filter:5, level:3, strategy:3, size:245469
filter:5, level:4, strategy:3, size:245469
filter:5, level:5, strategy:3, size:245469
filter:5, level:6, strategy:3, size:245469
filter:5, level:7, strategy:3, size:245469
filter:5, level:8, strategy:3, size:245469
filter:5, level:9, strategy:3, size:245469
filter:3, level:8, strategy:0, size:245487
filter:3, level:9, strategy:1, size:245493
filter:1, level:4, strategy:1, size:245503
filter:3, level:9, strategy:0, size:245521
filter:1, level:4, strategy:0, size:245529
filter:1, level:5, strategy:1, size:245533
filter:1, level:5, strategy:0, size:245559
filter:1, level:6, strategy:1, size:245584
filter:1, level:7, strategy:1, size:245584
filter:1, level:6, strategy:0, size:245606
filter:1, level:7, strategy:0, size:245606
filter:3, level:4, strategy:1, size:245663
filter:3, level:5, strategy:1, size:245668
filter:3, level:6, strategy:1, size:245669
filter:3, level:7, strategy:1, size:245669
filter:3, level:4, strategy:0, size:245696
filter:3, level:5, strategy:0, size:245700
filter:3, level:6, strategy:0, size:245701
filter:3, level:7, strategy:0, size:245701
filter:1, level:1, strategy:3, size:245704
filter:1, level:2, strategy:3, size:245704
filter:1, level:3, strategy:3, size:245704
filter:1, level:4, strategy:3, size:245704
filter:1, level:5, strategy:3, size:245704
filter:1, level:6, strategy:3, size:245704
filter:1, level:7, strategy:3, size:245704
filter:1, level:8, strategy:3, size:245704
filter:1, level:9, strategy:3, size:245704
filter:2, level:1, strategy:0, size:245967
filter:2, level:1, strategy:1, size:245967
filter:2, level:2, strategy:0, size:245967
filter:2, level:2, strategy:1, size:245967
filter:2, level:3, strategy:0, size:245967
filter:2, level:3, strategy:1, size:245967
filter:4, level:2, strategy:0, size:246294
filter:4, level:2, strategy:1, size:246294
filter:4, level:3, strategy:0, size:246309
filter:4, level:3, strategy:1, size:246309
filter:0, level:1, strategy:0, size:246391
filter:0, level:1, strategy:1, size:246391
filter:0, level:2, strategy:0, size:246391
filter:0, level:2, strategy:1, size:246391
filter:0, level:3, strategy:0, size:246391
filter:0, level:3, strategy:1, size:246391
filter:4, level:1, strategy:0, size:246407
filter:4, level:1, strategy:1, size:246407
filter:5, level:2, strategy:0, size:246920
filter:5, level:2, strategy:1, size:246920
filter:5, level:1, strategy:0, size:246926
filter:5, level:1, strategy:1, size:246926
filter:5, level:3, strategy:0, size:246955
filter:5, level:3, strategy:1, size:246955
filter:1, level:2, strategy:0, size:247380
filter:1, level:2, strategy:1, size:247380
filter:1, level:3, strategy:0, size:247380
filter:1, level:3, strategy:1, size:247380
filter:3, level:1, strategy:0, size:247619
filter:3, level:1, strategy:1, size:247619
filter:3, level:2, strategy:0, size:247704
filter:3, level:2, strategy:1, size:247704
filter:3, level:3, strategy:0, size:247725
filter:3, level:3, strategy:1, size:247725
filter:1, level:1, strategy:0, size:247811
filter:1, level:1, strategy:1, size:247811
filter:2, level:9, strategy:4, size:257312
filter:2, level:8, strategy:4, size:257451
filter:4, level:8, strategy:4, size:257506
filter:4, level:9, strategy:4, size:257519
filter:4, level:4, strategy:4, size:257536
filter:4, level:5, strategy:4, size:257539
filter:4, level:6, strategy:4, size:257546
filter:4, level:7, strategy:4, size:257546
filter:0, level:8, strategy:4, size:257721
filter:0, level:9, strategy:4, size:257721
filter:2, level:4, strategy:4, size:257737
filter:2, level:5, strategy:4, size:257759
filter:2, level:6, strategy:4, size:257759
filter:2, level:7, strategy:4, size:257759
filter:5, level:8, strategy:4, size:258068
filter:5, level:9, strategy:4, size:258075
filter:0, level:4, strategy:4, size:258081
filter:0, level:5, strategy:4, size:258105
filter:0, level:6, strategy:4, size:258105
filter:0, level:7, strategy:4, size:258105
filter:5, level:4, strategy:4, size:258190
filter:5, level:5, strategy:4, size:258203
filter:5, level:6, strategy:4, size:258230
filter:5, level:7, strategy:4, size:258230
filter:3, level:8, strategy:4, size:258614
filter:1, level:8, strategy:4, size:258625
filter:1, level:9, strategy:4, size:258625
filter:3, level:9, strategy:4, size:258626
filter:3, level:5, strategy:4, size:258783
filter:3, level:6, strategy:4, size:258783
filter:3, level:7, strategy:4, size:258783
filter:3, level:4, strategy:4, size:258784
filter:1, level:4, strategy:4, size:258847
filter:1, level:5, strategy:4, size:258872
filter:1, level:6, strategy:4, size:258922
filter:1, level:7, strategy:4, size:258922
filter:2, level:1, strategy:4, size:258953
filter:2, level:2, strategy:4, size:258953
filter:2, level:3, strategy:4, size:258953
filter:4, level:2, strategy:4, size:259066
filter:4, level:3, strategy:4, size:259070
filter:4, level:1, strategy:4, size:259143
filter:0, level:1, strategy:4, size:259394
filter:0, level:2, strategy:4, size:259394
filter:0, level:3, strategy:4, size:259394
filter:5, level:3, strategy:4, size:259786
filter:5, level:2, strategy:4, size:259810
filter:5, level:1, strategy:4, size:259811
filter:3, level:1, strategy:4, size:260389
filter:3, level:2, strategy:4, size:260449
filter:3, level:3, strategy:4, size:260473
filter:1, level:2, strategy:4, size:260490
filter:1, level:3, strategy:4, size:260490
filter:1, level:1, strategy:4, size:260568
filter:4, level:0, strategy:3, size:284075
filter:5, level:0, strategy:3, size:284320
filter:1, level:0, strategy:3, size:286960
filter:4, level:1, strategy:2, size:331440
filter:4, level:2, strategy:2, size:331440
filter:4, level:3, strategy:2, size:331440
filter:4, level:4, strategy:2, size:331440
filter:4, level:5, strategy:2, size:331440
filter:4, level:6, strategy:2, size:331440
filter:4, level:7, strategy:2, size:331440
filter:4, level:8, strategy:2, size:331440
filter:4, level:9, strategy:2, size:331440
filter:5, level:1, strategy:2, size:331550
filter:5, level:2, strategy:2, size:331550
filter:5, level:3, strategy:2, size:331550
filter:5, level:4, strategy:2, size:331550
filter:5, level:5, strategy:2, size:331550
filter:5, level:6, strategy:2, size:331550
filter:5, level:7, strategy:2, size:331550
filter:5, level:8, strategy:2, size:331550
filter:5, level:9, strategy:2, size:331550
filter:1, level:1, strategy:2, size:331823
filter:1, level:2, strategy:2, size:331823
filter:1, level:3, strategy:2, size:331823
filter:1, level:4, strategy:2, size:331823
filter:1, level:5, strategy:2, size:331823
filter:1, level:6, strategy:2, size:331823
filter:1, level:7, strategy:2, size:331823
filter:1, level:8, strategy:2, size:331823
filter:1, level:9, strategy:2, size:331823
filter:3, level:1, strategy:3, size:346952
filter:3, level:2, strategy:3, size:346952
filter:3, level:3, strategy:3, size:346952
filter:3, level:4, strategy:3, size:346952
filter:3, level:5, strategy:3, size:346952
filter:3, level:6, strategy:3, size:346952
filter:3, level:7, strategy:3, size:346952
filter:3, level:8, strategy:3, size:346952
filter:3, level:9, strategy:3, size:346952
filter:2, level:1, strategy:3, size:358276
filter:2, level:2, strategy:3, size:358276
filter:2, level:3, strategy:3, size:358276
filter:2, level:4, strategy:3, size:358276
filter:2, level:5, strategy:3, size:358276
filter:2, level:6, strategy:3, size:358276
filter:2, level:7, strategy:3, size:358276
filter:2, level:8, strategy:3, size:358276
filter:2, level:9, strategy:3, size:358276
filter:3, level:1, strategy:2, size:429431
filter:3, level:2, strategy:2, size:429431
filter:3, level:3, strategy:2, size:429431
filter:3, level:4, strategy:2, size:429431
filter:3, level:5, strategy:2, size:429431
filter:3, level:6, strategy:2, size:429431
filter:3, level:7, strategy:2, size:429431
filter:3, level:8, strategy:2, size:429431
...

【讨论】:

那么哪种组合为您带来了最小的输出? (懒得滚动和比较自己...... :) 挑战:现在可视化您的数据集,马克! :-) 哇,这是一个答案。我对你的想法和投入的时间感到惊讶。赞一个! pngcrush 实际上是在 1999 年开始的,就像你运行 ImageMagick 的循环一样,加上一些 shell 东西来选择最小的结果文件。 @CharlieC 抱歉,这是我使用的一个小脚本,因为stat 在 OSX 上是不同的。基本上,它包含这个stat -f "%Dz" "$1"【参考方案6】:

在压缩 PNG 时,我不会只依赖 ImageMagick(除非有一些超出您控制范围的原因迫使您使用 ImageMagick)。

比较 ImageMagick 的结果的一个很好的选择是 pngcrush,或者是它的更新的继任者 optipng

在优化和压缩方面,这两者通常都比 ImageMagick 取得更好的结果。通常,它们也比 IM 慢,因为它们可以暴力破解不同的方法,然后只保留最小的结果。

话虽如此,现在开始使用 ImageMagick...


使用convert 定义PNG 质量的标准方法是使用-quality levelfilter 参数。

不过,您可以使用-define png:... 控件组合获得的更细粒度的控件。

-quality 用于 PNG 与 JPEG 的质量设置非常不同(它只是一个从 0100 的整数)。

对于 PNG,它是 composed -- 由两个单个数字组成:

第一个数字(level)是(主要是)zlib 压缩级别,它可能从09(然而,0 的设置有一个特殊的含义:当你使用它时,你会得到 Huffman 压缩,而不是 zlib 压缩级别 0。这通常更好......奇怪但真实。)

第二位(filter)PNG数据编码过滤器类型(压缩前):

0 表示没有, 1 表示“子”, 2 表示“向上”, 3 表示“平均”, 4 表示“Paeth”,并且 5 表示“自适应”。

实际上会导致:

对于具有纯色序列的插图,使用“无”过滤器 (-quality 00) 进行 Huffman 压缩通常是最合适的。 对于自然景观照片,“自适应”过滤 (-quality 05) 通常是最好的。

要将其转换为命令行语法,请尝试以下设置:

 -define png:compression-level=0  \
 -define png:compression-filter=5 \ 
 -define png:compression-strategy=2 

最后,如果我想真正比较压缩后图像的不同(但接近)清晰度水平,我经常使用 Fred Weinstein 精彩的 flicker_cmp 脚本。

让你的妻子测试一下... :-)


P.S.:Here 是一个很好的关于 PNG 压缩技术的指南。

【讨论】:

我使用所有三个流行的 PNG 优化器以这个确切的顺序获得最佳压缩(是的,它确实有所不同):PNGout、Ad***G、OptiPNG。

以上是关于ImageMagick:PNG的无损最大压缩?的主要内容,如果未能解决你的问题,请参考以下文章

使用pngquant命令近乎无损压缩PNG图片大小减少70%左右

扫描仪扫描文件处理之scan_png_monochrome.py

png图片怎么通过代码实现压缩到指定的文件大小,比如5M压缩到200KB,比如用pngquant或imageMagick

Imagemagick 将 png 转换为 jxr

使用 imagemagick 无损旋转 PDF 文件

android 网络下载图片透明处变黑