PHP imagefilter函数参数IMG_FILTER_PIXELATE问题

Can some one explain the IMG_FILTER_PIXELATE parameters additional values in detail what is the range for each parameter, can they negative numbers values, float number values and what exactly do they do?

You have asked this about some of the other filters as well. Please read the manual page for imagefilter, on which you will discover that the first argument is the block size in pixels and the second argument is a boolean that changes the "advanced pixel mode", whatever that means.

What's the range? Well the second is a bool, so that'll be 0/1/true/false/whatever. But the first is the size of the blocks in the pixelation. Why would you think it might take a negative? What happens when you do give it a negative? Does it freak out? Make it a zero? Crash? Burn? Destroy the world? No. Freaking. Clue. Try it out yourself, it'll be fun! What's the worst that could happen.

For future reference, being the one that implemented IMG_FILTER_PIXELATE.

The two additional parameters works as follows:

  • $arg1: This is the block size in pixels, must be a positive, and a minimum of 1 (no effect)
  • $arg2: This determines hows smooth the pixelation process will be, the example on imagefilter displays how this looks.

A bit more in depth about the 'advanced' pixelation vs 'simple':

For simple mode, the color used for the block is the first pixel in that block, but for advanced mode the color used will be an "average" color of all the pixels in the block, meaning internally all pixels are iterated and added to an array of RGB values and the average color of that is used, meaning there will be used more CPU time calculating the actual color used.

Despite being an old post, I hope this may be useful for future readers.