Check pixels pattern
<p>How can I check for a pixel pattern in PHP?</p>

<p>I mean I wanna use as condition that pixel A has xxx value and the following pixel B has another value yyy.</p>

<p>This is what I wrote:</p>

<pre><code>$img = imagecreatefrompng("myimage.png"); 


$w = imagesx($img);
$h = imagesy($img);

for($y=0;$y&lt;$h;$y++) {
    for($x=0;$x&lt;$w;$x++) {
        $rgb = imagecolorat($img, $x, $y);
        $r = ($rgb &gt;&gt; 16) &amp; 0xFF;
        $g = ($rgb &gt;&gt; 8) &amp; 0xFF;
        $b = $rgb &amp; 0xFF;        
        echo "#".$r.$g.$b.",";
        $pixel = $r.$g.$b;
        if ($pixel == "481023" and $pixel+1???
    }
    echo "&lt;br /&gt;\r\n";
} 
</code></pre>

<p>I'd like to ask also if I can speed up the whole thing by incrementing the $x value by 2 every for cycle. This because I have a pattern of 2 pixels, maybe I can use something like:</p>

<pre><code>for($x=0;$x&lt;$w;$x+2) {
    //...
    if ($pixel == "xxx") {//check the following pixel}
    else if ($pixel == "yyy") {//check the previous pixel}
}
</code></pre>
