phpimagepnggdgdlib

In PHP, imagepng() accepts a filter parameter. How do these filters affect the function's output?


How do these filters affect the output of imagepng() in PHP?

The documentation simply says, "A special PNG filter, used by the imagepng() function" for each of them.

It seems that using PNG_NO_FILTER will reduce the filesize of the output, but other than that, I am unsure as to how it is affected. Any insight would be really appreciated.


Solution

  • According to the PNG Specifications at http://www.w3.org/TR/PNG-Filters.html The purpose of these filters is to prepare the image data for optimum compression.

    With the None filter, the scanline is transmitted unmodified; it is only necessary to insert a filter type byte before the data.

    The Sub filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel.

    The Up filter is just like the Sub filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor.

    The Average filter uses the average of the two neighbouring pixels (left and above) to predict the value of a pixel.

    The Paeth filter computes a simple linear function of the three neighbouring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value. This technique is due to Alan W. Paeth [PAETH].*