Imagick::importImagePixels
(No version information available, might only be in Git)
Imagick::importImagePixels — Imports image pixels
Description
$x
, int $y
, int $width
, int $height
, string $map
, int $storage
, array $pixels
) : bool
Imports pixels from an array into an image. The map
is usually
'RGB'. This method imposes the following constraints for the parameters: amount of pixels
in the array must match width
x height
x length of the map.
This method is available if Imagick has been compiled against ImageMagick version 6.4.5 or newer.
Parameters
-
x
-
The image x position
-
y
-
The image y position
-
width
-
The image width
-
height
-
The image height
-
map
-
Map of pixel ordering as a string. This can be for example RGB. The value 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.
-
storage
-
The pixel storage method. Refer to this list of pixel constants.
-
pixels
-
The array of pixels
Examples
Example #1 Imagick::importImagePixels() example
<?php
/* Generate array of pixels. 2000 pixels per color stripe */
$count = 2000 * 3;
$pixels =
array_merge(array_pad(array(), $count, 0),
array_pad(array(), $count, 255),
array_pad(array(), $count, 0),
array_pad(array(), $count, 255),
array_pad(array(), $count, 0));
/* Width and height. The area is amount of pixels divided
by three. Three comes from 'RGB', three values per pixel */
$width = $height = pow((count($pixels) / 3), 0.5);
/* Create empty image */
$im = new Imagick();
$im->newImage($width, $height, 'gray');
/* Import the pixels into image.
width * height * strlen("RGB") must match count($pixels) */
$im->importImagePixels(0, 0, $width, $height, "RGB", Imagick::PIXEL_CHAR, $pixels);
/* output as jpeg image */
$im->setImageFormat('jpg');
header("Content-Type: image/jpg");
echo $im;
?>
The above example will output something similar to:
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-imagick.importimagepixels.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.