imagemagick png imagemagick-convert libpng

ImageMagick: ¿Compresión máxima sin pérdida para PNG?



imagemagick-convert libpng (5)

Creo que está en los límites de la documentación de ImageMagick, o más allá, y le gustaría sugerirle que elabore su respuesta de manera empírica, o si obtiene una respuesta definitiva, al menos debe probarla de manera empírica.

No tengo acceso a sus imágenes, así que generé una imagen de referencia de la siguiente manera. Contiene un bloque de color sólido (rojo) fácilmente compresible, un degradado blanco y negro y un montón de ruido, por lo que hay algo que hace que la mayoría de los tipos de compresión sean felices o infelices allí.

Para probar si tiene compresión sin pérdida, le sugiero que convierta las imágenes al formato PPM . Consulte here . Esto no contiene fecha, tiempo ni estadísticas ni nada, sino datos y tamaño de imagen puros en un formato extremadamente simple, lo que permite comparar si los valores de los píxeles han cambiado a través de la compresión.

Luego escribí una secuencia de comandos de la siguiente manera para comprimir la imagen de referencia utilizando todos los filtros, estrategias y niveles posibles para ver los tamaños de archivo y si han sufrido alguna pérdida y, por lo tanto, son diferentes de la imagen de PPM referencia:

Aquí está el guión:

#!/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

Todos los archivos se compararon de forma idéntica, por lo que no parece haber ninguna pérdida de compresión con ninguno de los parámetros que utilicé. Los tamaños salieron de la siguiente manera:

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

Obviamente, sus números serán diferentes, ya que sus imágenes son diferentes, por lo que tendrá que ver qué funciona para sus datos, pero esperamos que esto sea un punto de partida.

Tenga en cuenta que si ordeno lo anterior por tamaño, obtengo esto:

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 ...

Me gustaría lograr una compresión máxima al guardar en un PNG sin pérdida usando ImageMagick. Estoy haciendo la conversión por lotes de muchos PSDs.

Intenté algunas cosas, pero me parece que la imagen PNG resultante no es tan nítida como la imagen original, aunque mi esposa no la puede ver.

Estos son los argumentos actuales con los que estoy jugando:

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

Según: http://www.imagemagick.org/script/command-line-options.php#define

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

Eso significa:

  • filtro de compresión es 1 (Sub)
  • nivel de compresión máximo 9
  • la estrategia de compresión es 2 huffman_only (por lo que no se filtra, aunque este filtro de compresión no tendrá pérdidas)

De acuerdo con la documentación: "los valores válidos son de 0 a 4, lo que significa que la estrategia de compresión ZLIB es predeterminada, filtrada, huffman_only, rle y fija. 1.2.2.2), los valores 3 y 4, respectivamente, utilizarán la estrategia predeterminada zlib en su lugar ".

Por cierto, mis imágenes son 960x720 píxeles.

(Si utilizo la estrategia de compresión predeterminada 0, obtengo archivos grandes. Puede ser que el filtro de compresión de 9 y la estrategia de compresión de 0 estén produciendo imágenes de menor tamaño, pero aún no estoy seguro de si es sin pérdida).

Preguntas:

  1. ¿Es esta compresión sin pérdida? Si no, ¿dónde está el error?
  2. ¿Alguna idea de cómo lograr una mejor compresión sin pérdida?

El algoritmo de compresión de desinflado utiliza una ventana de historial de 65K. La compresión PNG tiende a ser bastante lenta porque el proceso tiene que comparar secuencias de bytes en el flujo de compresión con las de la ventana.

Puede controlar la velocidad de la compresión limitando la búsqueda de la ventana. Solo puede buscar coincidencias en la mitad del búfer para acelerar el proceso (como riesgo de compresión más baja).

En JPEG, la compensación es entre calidad y tamaño. En la compresión PNG, la compensación es entre velocidad y tamaño.

En cualquier caso, el proceso de compresión PNG siempre es sin pérdidas.


La mejor compresión que obtuve fue la siguiente:

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

Los resultados:

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

Si alguien sabe una manera mejor, dime por favor. No pude encontrar.


No confiaría solo en ImageMagick, al comprimir PNG (a menos que haya alguna razón fuera de tu control que te obligue a ImageMagick).

Una buena alternativa para comparar los resultados de ImageMagick contra, es pngcrush , o un sucesor más nuevo, optipng .

Ambos en general logran mejores resultados cuando se trata de optimización y compresión que ImageMagick. Con frecuencia, también son más lentos que los mensajes instantáneos, ya que pueden utilizar diferentes métodos de fuerza bruta y luego mantener solo el resultado más pequeño.

Dicho esto, ahora con ImageMagick ...

La forma estándar de definir la calidad PNG con convert es con el -quality {level}{filter} .

Sin embargo, tiene razón al usar los controles más -define png:... que obtiene al usar una combinación de los -define png:...

-quality para PNG es muy diferente a la configuración de calidad de JPEG (que simplemente es un número entero de 0 a 100 ).

Para PNG está compuesto , compuesto por dos dígitos simples:

  • El primer dígito ( {nivel} ) es (en gran medida) el nivel de compresión zlib , y puede ir de 0 a 9 .
    (Sin embargo, la configuración de 0 tiene un significado especial: cuando lo usas obtendrás la compresión Huffman, no el nivel de compresión zlib 0. Esto suele ser mejor ... Raro pero cierto).

  • El segundo dígito ({filtro}) es el tipo de filtro de codificación de datos PNG (antes de que se comprima):

    • 0 significa ninguno,
    • 1 significa "sub",
    • 2 significa "arriba",
    • 3 significa "promedio",
    • 4 significa "Paeth", y
    • 5 significa "adaptativo".

En términos prácticos eso resulta en:

  • Para las ilustraciones con secuencias sólidas de color, la compresión Huffman con un filtro "ninguno" ( -quality 00 ) suele ser la más apropiada.
  • Para fotos de paisajes naturales, un filtro "adaptativo" ( -quality 05 ) es generalmente el mejor.

Para traducir esto a su sintaxis de línea de comandos, pruebe la siguiente configuración:

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

Por último, si realmente quiero comparar los diferentes (pero cercanos) niveles de nitidez de una imagen después de la compresión, con frecuencia utilizo el maravilloso script flicker_cmp de Fred Weinstein.

Deja que tu esposa lo pruebe ... :-)

PD: Here hay una buena guía sobre los aspectos técnicos de la compresión PNG.


Me pasé medio día jugando. Hice cambiar el tamaño de las imágenes a 360x240px. Obtuve el mejor resultado con:

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