Solved

Use ImageColorAt to map out pixel locations.

Posted on 2007-04-01
6
252 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:yodercm
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make checkboxes execute queries on click 8 37
Make check boxes work 8 47
How to remove  "0":  in a json string 4 20
Why is my implode function empty 8 20
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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 …

697 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