Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Use ImageColorAt to map out pixel locations.

Posted on 2007-04-01
6
Medium Priority
?
256 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
NickVd earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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 count occurrences of each item in an array.
Suggested Courses

618 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