PHP | Imagick exportImagePixels() Function
Last Updated :
19 Jul, 2019
The Imagick::exportImagePixels() function is an inbuilt function in PHP which is used to exports raw image pixels in the form of an array. The map defines the ordering of the exported pixels. The size of the returned array is width*height*strlen(map).
Syntax:
array Imagick::exportImagePixels( $x, $y, $width, $height, $map, $STORAGE )
Parameters: This function accepts six parameters as mentioned above and described below:
- $x: It holds the x-coordinate of the exported area.
- $y: It holds the y-coordinate of the exported area.
- $width: It holds the width of the exported area.
- $height: It holds the height of the exported area.
- $map: It holds the ordering of the exported pixels. For example “RGB”. The valid characters of the map are: R, G, B, A, O, C, Y, M, K, I and P.
- $STORAGE: It holds the pixel type constants.
Return Value: This function returns an array containing the pixels values.
Program:
<?php
$image = new Imagick();
$image ->newPseudoImage(0, 0, "magick:rose" );
$pixels = $image ->exportImagePixels(5, 5, 3, 3, "RGB" , Imagick::PIXEL_CHAR);
var_dump( $pixels );
?>
|
Output:
array(27) {
[0]=> int(51) [1]=> int(47) [2]=> int(44) [3]=> int(50) [4]=> int(45)
[5]=> int(42) [6]=> int(45) [7]=> int(42) [8]=> int(43) [9]=> int(58)
[10]=> int(50) [11]=> int(46) [12]=> int(56) [13]=> int(48) [14]=> int(45)
[15]=> int(51) [16]=> int(46) [17]=> int(44) [18]=> int(66) [19]=> int(58)
[20]=> int(56) [21]=> int(65) [22]=> int(57) [23]=> int(53) [24]=> int(61)
[25]=> int(55) [26]=> int(51)
}
Reference: https://www.php.net/manual/en/imagick.exportimagepixels.php
Share your thoughts in the comments
Please Login to comment...