Solved

Use ImageColorAt to map out pixel locations.

Posted on 2007-04-01
6
245 Views
Last Modified: 2009-12-16
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
0
Comment
Question by:JPERKS1985
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:NickVd
Comment Utility
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
 
LVL 1

Author Comment

by:JPERKS1985
Comment Utility
didn't work :(. It should output it in x and y.
0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Accepted Solution

by:
NickVd earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:JPERKS1985
Comment Utility
didn't work/
0
 
LVL 1

Author Comment

by:JPERKS1985
Comment Utility
"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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now