Solved

Use ImageColorAt to map out pixel locations.

Posted on 2007-04-01
6
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:NickVd
ID: 18831427
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
ID: 18831460
didn't work :(. It should output it in x and y.
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 18831510
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 5

Accepted Solution

by:
NickVd earned 500 total points
ID: 18831936
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
ID: 18832917
didn't work/
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 18832919
"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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 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