Based on your given code, we can reverse-engineer the structure of $arr2 to (assuming R, G and B are integer from 0 to 255):
$arr2 = array(
0 => array(
0 => array(
"R" => 128,
"G" => 64,
"B" => 255
),
1 => array(
...
)
)
);
Given that your $SIZE is set to 256, you will have a total of 256*256=65536 arrays further containing arrays with key-values for R, G and B, resulting in total of 256*256*3=196608 integers in 3 levels of hierarchy. No surprise your code is slow!
I think the best strategy here is to try to reduce the total number of items in your array.
Given that instead of encoding single cells as "R, G, B" triples, you could encode all values in a single integer. Such as instead of:
0 => array( "R" => $r, "G" => $g, "B" => $b )
Given that 0<=r,g,b<=255, you could encode $arr2 as:
0 => ($r<<16 + $g<<8 + $b);
Now of course you need to unpack the color value inside your loop as well. This can be achieved by:
$col = $arr2[$y][$x];
$col_b = ($col&255);
$col_g = ($col>>8)&255;
$col_r = ($col>>16)&255;
$r .= $col_r.":";
$g .= $col_g.":";
$b .= $col_b.":";
This modification alone would cut one level of hierarchy from your array completely.
While running your original code with $SIZE=256, my average execution speed in my settings was 0.30 secs. With the given refactoring, I was able to reduce this to 0.10 secs cutting your calculation time to 1/3 of the original.
You will still have a lot of work to do if you wish to improve the performance, but I hope this gives you an idea on how you could proceed.
$SIZE-1calculation once at the beginning and store it, rather than doing it on each iteration.