1

I'm making a script to check if any image is covered in a single color. My idea is resizing the image to 1% of it's size and then walk through every pixel untill the script finds a pixel which is another color then the first one. If it finds such a pixel, the image is not completely 1 color.

Now I have a 1360x768 png image from which every pixel is completely white. When I resize this image to 1% of its size and save it, every pixel is still completely white. I checked this with Photoshop. Though, when I'm trying to read all the pixels from either the memory or the saved image, imagecolorat states that not all pixels are exactly the same color.

These are the results I get from imagecolorat / imagecolorsforindex for the first four pixels:

0x0: 16711422 Array ( [red] => 254 [green] => 254 [blue] => 254 [alpha] => 0 )
0x1: 16711422 Array ( [red] => 254 [green] => 254 [blue] => 254 [alpha] => 0 )
0x2: 16711422 Array ( [red] => 254 [green] => 254 [blue] => 254 [alpha] => 0 )
0x3: 16777215 Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 0 ) 

As you can see, the fourth pixel differs in color (#ffffff) against the first 3 (#fefefe). The first three though, are the wrong color since #ffffff / 255, 255, 255 would be white.

I've found these two questions, but I don't know how to apply this for any color: PHP: how to express "near white" as a color? Two unusual PHP operators used together to get image pixel color, please explain

Can anyone tell me if there's a fix for this?

Community
  • 1
  • 1
ev8
  • 83
  • 9

0 Answers0