Solved

Image Magic: Image Report

Posted on 2006-07-12
6
251 Views
Last Modified: 2008-03-17
This is kind of an oddball question, but if you know imagemagic, I imagine it is an easy one. (Could be wrong)

What I would like to do is to have image magic read each pixel of and image, and report the RGB value in html usable form. (ie: 00FF33) On top of that, I would like to print a blurb at the beginning and the end of each "row" of pixels.

So output of a 4 pixel image might be:

begin_row
112233 112233
end_row
begin_row
FF44DD AABBC9
end_row

It is important that it be easy to decipher where I might be able to add something to the beginning or end of the RGB numbers printed out. (I will probably edit the output eventually)

Any ideas on how to print HTML values for each pixel, with a blurb for beginning and ending a row in the image?
0
Comment
Question by:stakor
  • 4
6 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 451 total points
ID: 17095511
I haven't tested this... but it should be pretty close.
I'm not sure the format the get: pixel returns.  The documentation made it sound like it is already in hex, so you should be all good.  If it returns an integer array (1 element for red, green, blue), you can use this instead:
    printf "%x%x%x ", $image->get("pixel[$row,$col]");




#!/usr/local/bin/perl

use Image::Magick;
my($image, $x);

$image = Image::Magick->new;
$x = $image->Read('file.jpg');
warn "$x" if "$x";



$cols=$image->get('columns');
$rows=$image->get('rows');

for($row=1; $row<=$rows; $row++){
      print "begin_row\n";
      for($i=1; $i<=$cols; $i++){
            print $image->get("pixel[$row,$col]") . " ";
      }
      print "\nend_row\n";
}

0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17096967
>> Any ideas on how to print HTML values for each pixel

What do you mean by HTML values?

0
 

Author Comment

by:stakor
ID: 17101266
As far as the HTML Values, I was talking about the Hex values 0-255 for RGB. 00-FF So "00 R 11 G FF B" = "0011FF"
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:stakor
ID: 17101750
The results when I run Adam's program are like:

begin_row
3598,5140,2056,0 ....
end_row

I imagine the numbers are values for R G anb B, but I have no idea what the fourth one is. I was also hoping to get the numbers into hex. Any Ideas?
0
 

Author Comment

by:stakor
ID: 17102856
As it turns out I am an idiot. The incase it doesn't work, please use ____ works fine... Sorry about that. Thanks for your answer.
0
 

Author Comment

by:stakor
ID: 17104748
#!/usr/local/bin/perl

use Image::Magick;
my($image, $x);

$image = Image::Magick->new;
$x = $image->Read('file.jpg');
warn "$x" if "$x";

$cols=$image->get('columns');
$rows=$image->get('rows');

for($row=1; $row<=$rows; $row++){
     print "begin_row\n";
     for($i=1; $i<=$cols; $i++){
          printf "%x%x%x ", $image->get("pixel[$i,$row]");
     }
     print "\nend_row\n";
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 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