Link to home
Start Free TrialLog in
Avatar of JPERKS1985
JPERKS1985

asked on

Use ImageColorAt to map out pixel locations.

I need to know how to use ImageColorAt to map out pixels in a png image. Then echo the results like this,

Point 1 : X - 1, Y - 19
Point 2 : X - 4, Y - 36
Point 3 : X - 6, Y - 11

It will be a loop, I know that much. Thanks
Avatar of NickVd
NickVd

This is completely untested, but it should produce a (very large, depending on image size) two dimensional array with each pixel's colour value, so pixel x-56, y-22 will have a colour of $rgbValues[56][22].
<?php
$img = ImageCreateFromPng("<YOURIMAGE>.png");
$imgWidth = imagesx($img);
$imgHeight = imagesy($img);

for($x=1 ; $x<=$imgWidth ; $x++) {
  for($y=1 ; $y<=$imgHeight ; $y++) {
    $rgbValues[$x][$y] = ImageColorAt($img, $x, $y);
  }
}
?>

Hope this helps!
Avatar of JPERKS1985

ASKER

didn't work :(. It should output it in x and y.
Building on NickVd's code, just add another loop to print it.

for($x=1 ; $x<=$imgWidth ; $x++) {
  for($y=1 ; $y<=$imgHeight ; $y++) {
    echo "X=$x  Y=$y  Color=" . ImageColorAt($img, $x, $y);
  }
}
ASKER CERTIFIED SOLUTION
Avatar of NickVd
NickVd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
didn't work/
"After separating all the characters, it time to get the individual pixel point (x, y) of each pixel (1px width x height) in a character and store them for later comparison. The function we will be using is the "ImageColorAt", which basically gets the index of the color of a pixel. Using a loop to go through every single pixel, you would be able to filter out the white pixels apart from the pixels that forms the character (Table 1.0). Do this for the rest of the different characters and you should have a completed pixel index library for this kind of  image. (Table 2.0) show the complete pixel index librar.."