Please help me to count number of pixels in image, or put out the array of RGB.
So this is the script thet give me one element from array:
The number of pixels in an image is simply the height multiplied by the width.
However, I think this is what you want:
<?php
$img = "1.png";
$imgHand = imagecreatefrompng("$img");
$imgSize = GetImageSize($img);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];
echo '<img src="'.$img.'"><br><br>';
// Define a new array to store the info
$pxlCorArr= array();
for ($l = 0; $l < $imgHeight; $l++) {
// Start a new "row" in the array for each row of the image.
$pxlCorArr[$l] = array();
for ($c = 0; $c < $imgWidth; $c++) {
$pxlCor = ImageColorAt($imgHand,$c,$l);
// Put each pixel's info in the array
$pxlCorArr[$l][$c] = ImageColorsForIndex($imgHand, $pxlCor);
}
}
print_r($pxlCorArr);
?>
This will store all the pixel data for the image in the pxlCor
and pxlCorArr
arrays, which you can then manipulate to output what you want.
The array is a 2d array, meaning you can refrence an individual pixel with an $pxlCorArr[y][x]
starting at [0][0]
.