I need to use PHP to read every pixel in a image. It's for graphical password project. When user chooses a password, they will select some area on the image. and I'm trying to do it by pixel value. Is it possible??
Yes, you can get the pixel "value" as in color using imagecolorat()
.
$color = imagecolorat($resource, $x, $y);
Where $resource
is your image resource, and $x
, $y
are the coordinates of the pixel you want to get the color of.
You can iterate through all of the pixels like this. Note that this can be an expensive task depending on how large the image is.
$width = imagesx($resource);
$height = imagesy($resource);
for($x = 0; $x < $width; $x++) {
for($y = 0; $y < $height; $y++) {
// pixel color at (x, y)
$color = imagecolorat($resource, $x, $y);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With