Prev
MagickWand For PHP
Manual


Next

MagickGetImagePixels

MagickGetImagePixels -- extracts pixel data from the current active image and returns it an array

Description

array MagickGetImagePixels( MagickWand mgck_wnd, int x_offset, int y_offset, float columns, float rows, string map, int storage_type )

Extracts pixel data from the current active image and returns it an array. The returned pixel data will be in scanline (left-to-right) order, top-to-bottom. The columns and rows parameters specify the width and height (respectively) of the pixel area to be returned. The map string parameter specifies the type and ordering of the pixel color component data to be returned. It can be any combination or order of R = red G = green B = blue A = alpha (0 is transparent) O = opacity (0 is opaque) C = cyan Y = yellow M = magenta K = black I = intensity (for grayscale) P = pad For each letter in map, there will be a corresponding color component value, for each pixel in the image, in the returned array. So, the size of the returned array will be EXACTLY: columns * rows * strlen(map) storage_type must be a StorageType constant, one of the following: MW_CharPixel MW_ShortPixel MW_IntegerPixel MW_LongPixel MW_FloatPixel MW_DoublePixel If storage_type is MW_FloatPixel or MW_DoublePixel, the pixel color component values in the returned array will be of type PHP double, and normalized [0..1]. If storage_type is MW_IntegerPixel or MW_LongPixel, the pixel color component values in the returned array will be of type PHP double, in order to accomodate the C maximum values of the corresponding C datatypes (integer and long). The other StorageType constants, MW_CharPixel and MW_ShortPixel, the pixel color component values in the returned array to be of type PHP integer. Example MagickGetImagePixels() called as follows: MagickGetImagePixels( $mgck_wnd, 0, 0, 24, 20, 'GARB', MW_CharPixel ); would return an array comprised of the pixel color component data of the pixels starting at point (0, 0), encompassing an area with a width of 300 pixels, and a height of 200 pixels, from the current active image of the MagickWand $mgck_wnd. The length of the returned array would be 1920, that is, 24 * 20 * 4 as per the above formula columns * rows * strlen(map) Its values would look something like the following: Array { [0] => 106, [1] => 24, [2] => 5, [3] => 70, //pixel (0,0) [4] => 116, [5] => 56, [6] => 85, [7] => 36, //pixel (1,0) [8] => 23, [9] => 77, [10] => 23, [11] => 180, //pixel (2,0) [12] => 56, [13] => 88, [14] => 79, [15] => 240, //pixel (3,0) ... [1908] => 19, [1909] => 229, [1910] => 98, [1911] => 39, //(21,19) [1912] => 89, [1913] => 186, [1914] => 153, [1915] => 209, //(22,19) [1916] => 226, [1917] => 167, [1918] => 219, [1919] => 125 //(23,19) } 'GARB' is just 'RGBA' jumbled -- the order doesn't matter -- and it specifies that the returned array be made up of the green, alpha, red and blue color component values of each pixel in the requested pixel area.


A description of each parameter follows:

mgck_wnd A MagickWand resource
x_offset The x ordinate of the pixel at the top left corner of the region of pixels you want to extract
y_offset The y ordinate of the pixel at the top left corner of the region of pixels you want to extract
columns The width of the region of pixels you want to extract
rows The height of the region of pixels you want to extract
map This string reflects the expected types and ordering of the pixel color component data array. See above.
storage_type A StorageType constant; defines the numerical C datatype of the pixel color component data to be returned


Prev
MagickGetImageMimeType
Up Next
MagickGetImageProfile