Fredrik Eriksson - 2012-09-03 18:14:39
Speed and optmization comes into mind when you are using nested for-loops that goes through all pixels in an image.
A quick look and I found the following:
$red = round(round(($rgb['red'] / 0x33)) * 0x33);
$green = round(round(($rgb['green'] / 0x33)) * 0x33);
$blue = round(round(($rgb['blue'] / 0x33)) * 0x33);
The inner round is need because it might end up as a float. But then the rounded number (Integer) is multiplied by 0x33 (51) and two integers multiplied can't result in a float but only a Integer.
Faster code would be:
$red = round($rgb['red'] / 0x33) * 0x33;
$green = round($rgb['green'] / 0x33) * 0x33;
$blue = round($rgb['blue'] / 0x33) * 0x33;
This small change gave me about 20% faster execution.