how to count number of pixels in image (php)

前端 未结 1 926
走了就别回头了
走了就别回头了 2021-01-22 12:12

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:



        
1条回答
  •  佛祖请我去吃肉
    2021-01-22 12:49

    The number of pixels in an image is simply the height multiplied by the width.

    However, I think this is what you want:



    '; // 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].

    0 讨论(0)
提交回复
热议问题