# 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
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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!
0
Author Commented:
didn't work :(. It should output it in x and y.
0
ArtistCommented:
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);
}
}
0
Commented:
No no no... There isn't a need for two different loops... just echo the value in the main loop..

...
for(\$x=1 ; \$x<=\$imgWidth ; \$x++) {
for(\$y=1 ; \$y<=\$imgHeight ; \$y++) {
\$rgb = ImageColorAt(\$img, \$x, \$y);
\$rgbValues[\$x][\$y] = \$rgb; // for later use...
echo "X=\$x  Y=\$y  Color=" . \$rgb;
}
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
didn't work/
0
Author Commented:
"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.."
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.