get color value of all pixels

476 views Asked by At

I want to get color value of the pixels using php and imagick. I tried out the folowing code.But does't seemed to be working properly as I expected. Here is my code.

    <?php
$image = new imagick( 'C:\Users\me\Desktop\bb.png' );


for($x=1;$x<=4;$x++)
{
    for($y=1;$y<=4;$y++)
    {
        $pixel= $image->getImagePixelColor( $x, $y);

        $red=$pixel->getColorValue(Imagick::COLOR_RED).PHP_EOL;
        $green=$pixel->getColorValue(Imagick::COLOR_GREEN).PHP_EOL;
        $blue=$pixel->getColorValue(Imagick::COLOR_BLUE).PHP_EOL;
        $alpha=$pixel->getColorValue(Imagick::COLOR_ALPHA).PHP_EOL;


    }
}
print_r("red at 3rd pixel :"+$red[3]);

According to the above code it should read 16pixels. But it reads only 3 pixels. That means if I print_r($red[4]) it gives Uninitialized string offset: 4 in C:\xampp\htdocs\imageP\ab2.php on line 32; I can't find any error. Please help me.

0

There are 0 answers