Trying to get pixel color data for every pixel in an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
merovinq
Posts: 4
Joined: 2010-12-18T11:46:18-07:00
Authentication code: 8675308

Trying to get pixel color data for every pixel in an image

Post by merovinq »

The images will be smaller like 300x60 or so on average... but the method I am using is way too slow... is there a faster way than the php example below?

Code: Select all

$image = 'test.jpg';
$imageSize = getimagesize($image);
for($w=0; $w<=$imageSize[0]; $w++){
  	for($h=0; $h<=$imageSize[1]; $h++){
  		$txt[$w][$h] = exec('convert '.$image.'[1x1+'.$w.'+'.$h.'] txt:');	
  	}
}
debug($txt);
Below is an example of how I would like the data to look. Actually just rgb values would be fine too.

Code: Select all

Array
(
    [0] => Array
        (
            [0] => 0,0: (255,255,255)  #FFFFFF  white
            [1] => 0,0: (255,255,255)  #FFFFFF  white
            [2] => 0,0: (255,255,255)  #FFFFFF  white
            [3] => 0,0: (255,255,255)  #FFFFFF  white
            [4] => 0,0: (255,255,255)  #FFFFFF  white
            [5] => 0,0: (255,255,255)  #FFFFFF  white
            [6] => 0,0: (255,255,255)  #FFFFFF  white
            [7] => 0,0: (255,255,255)  #FFFFFF  white
            [8] => 0,0: (250,250,250)  #FAFAFA  grey98
            [9] => 0,0: (255,255,255)  #FFFFFF  white
            [10] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [11] => 0,0: (255,255,255)  #FFFFFF  white
            [12] => 0,0: (255,255,255)  #FFFFFF  white
            [13] => 0,0: (248,248,248)  #F8F8F8  rgb(248,248,248)
            [14] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [15] => 0,0: (255,255,255)  #FFFFFF  white
            [16] => 0,0: (255,255,255)  #FFFFFF  white
            [17] => 0,0: (255,255,255)  #FFFFFF  white
            [18] => 0,0: (255,255,255)  #FFFFFF  white
            [19] => 0,0: (254,254,254)  #FEFEFE  rgb(254,254,254)
            [20] => 0,0: (252,252,252)  #FCFCFC  grey99
        )

    [1] => Array
        (
            [0] => 0,0: (255,255,255)  #FFFFFF  white
            [1] => 0,0: (255,255,255)  #FFFFFF  white
            [2] => 0,0: (255,255,255)  #FFFFFF  white
            [3] => 0,0: (255,255,255)  #FFFFFF  white
            [4] => 0,0: (255,255,255)  #FFFFFF  white
            [5] => 0,0: (255,255,255)  #FFFFFF  white
            [6] => 0,0: (255,255,255)  #FFFFFF  white
            [7] => 0,0: (255,255,255)  #FFFFFF  white
            [8] => 0,0: (255,255,255)  #FFFFFF  white
            [9] => 0,0: (250,250,250)  #FAFAFA  grey98
            [10] => 0,0: (250,250,250)  #FAFAFA  grey98
            [11] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [12] => 0,0: (254,254,254)  #FEFEFE  rgb(254,254,254)
            [13] => 0,0: (252,252,252)  #FCFCFC  grey99
            [14] => 0,0: (250,250,250)  #FAFAFA  grey98
            [15] => 0,0: (255,255,255)  #FFFFFF  white
            [16] => 0,0: (248,248,248)  #F8F8F8  rgb(248,248,248)
            [17] => 0,0: (248,248,248)  #F8F8F8  rgb(248,248,248)
            [18] => 0,0: (251,251,251)  #FBFBFB  rgb(251,251,251)
            [19] => 0,0: (255,255,255)  #FFFFFF  white
            [20] => 0,0: (255,255,255)  #FFFFFF  white
        )
);

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trying to get pixel color data for every pixel in an ima

Post by fmw42 »

Withdrawn -- I see you are already converting to txt: format. Sorry.


You might try converting to Netpbm form such ppm for color in ascii output format. Perhaps it will be faster. See http://netpbm.sourceforge.net/doc/ppm.html

Anthony is the expert on NetPBM. He can help you further if NetPBM seems reasonable to him as being faster
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Trying to get pixel color data for every pixel in an ima

Post by anthony »

As you know how to get the output from the Enumerated Pixel Format (TXT:) the problem devolves down to reading and storing the output strings in a PHP array.

That is however a PHP problem not an ImageMagick Problem. However I am sure someone such as RubbleWeb can help you further.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply