I\'d like to achieve a maximum amount of compression when saving to a lossless PNG using ImageMagick. I\'m doing batch conversion of many PSDs.
I tried a few things,
I spent half a day playing. I did resize images to 360x240px. I got the best result with:
convert -depth 24 -define png:compression-filter=2 \
-define png:compression-level=9 -define png:compression-strategy=1
I think you are at, or beyond, the limits of the ImageMagick documentation and would like to suggest you work out your answer empirically - or if you do get a definitive answer, that you at least test it empirically.
I don't have access to your images, so I generated a reference image myself, as follows. It contains a readily compressible block of solid colour (red), a black-white gradient and a bunch of noise, so there is something to make most types of compression happy or unhappy in there.
In order to test whether you have lossless compression, I would suggest you convert images to PPM
format - see here. This contains no date, or time or statistics or anything but pure image data and size in an extremely simple format - thereby allowing comparison of whether pixel values have changed through compression.
Then I wrote a script as follows to compress the reference image using all the possible filters, strategies and levels to see the filesizes and if they have suffered any losses and are therefore different from the reference PPM
image:
Here is the script:
#!/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
All files compared identically, so there doesn't seem to be any compression loss with any of the parameters I used. The sizes came out as follows:
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
Obviously your numbers will be different, as your images are different, so you will have to see what works for your data - but hopefully this will be a starting point.
Note that if I sort the above by size, I get this:
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
...
I would not rely on ImageMagick only, when compressing PNGs (unless there is some reason outside your own control that forces you to ImageMagick).
A good alternative to compare ImageMagick's results against, is pngcrush, or a newer successor to it, optipng.
Both of these do in general achieve better results when it comes to optimization and compression than ImageMagick does. Frequently, they are also slower than IM, because they can brute-force different methods, and then keep the smallest result only.
Having said that, now on with ImageMagick...
The standard way to define PNG quality with convert
is with the -quality {level}{filter}
parameter.
You are right in using the more fine-grained controls you gain by using a combination of -define png:...
controls, though.
-quality
for PNG is very unlike JPEG's quality setting (which simply is an integer from 0
to 100
).
For PNG it is composed -- composed by two single digits:
The first digit ({level}) is (largely) the zlib compression level, and it may go from 0
to 9
.
(However, the setting of 0
has a special meaning: when you use it you'll get Huffman compression, not zlib compression level 0. This is often better... Weird but true.)
The second digit ({filter}) is the PNG data encoding filter type (before it is compressed):
In practical terms that results in:
-quality 00
) is typically the most appropriate.-quality 05
) is generally the best.To translate this into your command line syntax, try the following setting:
-define png:compression-level=0 \
-define png:compression-filter=5 \
-define png:compression-strategy=2
Last, if I want to really compare the different (but close) sharpness levels of an image after compression, I frequently make use of Fred Weinstein's wonderful flicker_cmp script.
Let your wife test it... :-)
P.S.: Here is a good guide about the technicalities of PNG compression.
The deflate compression algorithm uses a 65K history window. PNG compression tends to be rather slow because the process has to compare byte sequences in the compression stream with the those in the window.
You can control the speed of the compression by limiting the search of window. You might only search half the buffer for matches to speed up the process (as the risk of lower compression).
In JPEG, the tradeoff is between quality and size. In PNG compression, the tradeoff is between speed and size.
In any event, the PNG compression process is always lossless.
The best compression I got was as follows:
convert wallpsw.png -resize 1024x768 -quality 95 \
-depth 8 wallpsw-q95-r1024x768-d8.png
The results:
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
If anyone knows a better way, tell me please. I could not find.