Solved

Image Magic: Image Report

Posted on 2006-07-12
6
238 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

11 Experts available now in Live!

Get 1:1 Help Now