Saturday, September 28, 2024
Google search engine
HomeLanguagesPHP | Imagick exportImagePixels() Function

PHP | Imagick exportImagePixels() Function

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
  
// Create new Imagick object
$image = new Imagick();
  
// Use newPseudoImage() function
// to create new image
$image->newPseudoImage(0, 0, "magick:rose");
  
// Use exportImagePixels() function
// to export the image pixels
$pixels = $image->exportImagePixels(5, 5, 3, 3, "RGB", Imagick::PIXEL_CHAR);
  
// Display the output array
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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments