PHP 8.3.4 Released!

Imagick::exportImagePixels

(PECL imagick 2 >=2.3.0, PECL imagick 3)

Imagick::exportImagePixels画像の生のピクセルをエクスポートする

説明

public Imagick::exportImagePixels(
    int $x,
    int $y,
    int $width,
    int $height,
    string $map,
    int $STORAGE
): array

画像のピクセルを配列にエクスポートします。map には、エクスポートするピクセルの順序を指定します。 返される配列の大きさは width * height * strlen(map) となります。 このメソッドは、ImageMagick バージョン 6.4.7 以降で Imagick をコンパイルした場合に使用可能です。

パラメータ

x

エクスポートする範囲の X 座標。

y

エクスポートする範囲の Y 座標。

width

エクスポートする範囲の幅。

height

エクスポートする範囲の高さ。

map

エクスポートするピクセルの順序。"RGB" など。 map で使える文字は R, G, B, A, O, C, Y, M, K, I および P です。

STORAGE

ピクセル型定数 を参照ください。

戻り値

ピクセルの値を含む配列を返します。

エラー / 例外

エラー時に ImagickException をスローします。

例1 Imagick::exportImagePixels() の使用法

画像のピクセルを配列にエクスポートします。

<?php

/* 新しいオブジェクトを作成します */
$im = new Imagick();

/* 新しい画像を作成します */
$im->newPseudoImage(0, 0, "magick:rose");

/* 画像のピクセルをエクスポートします。 */
$pixels = $im->exportImagePixels(10, 10, 2, 2, "RGB", Imagick::PIXEL_CHAR);

/* 出力します */
var_dump($pixels);
?>

上の例の出力は以下となります。

array(12) {
  [0]=>
  int(72)
  [1]=>
  int(64)
  [2]=>
  int(57)
  [3]=>
  int(69)
  [4]=>
  int(59)
  [5]=>
  int(43)
  [6]=>
  int(124)
  [7]=>
  int(120)
  [8]=>
  int(-96)
  [9]=>
  int(91)
  [10]=>
  int(84)
  [11]=>
  int(111)
}

add a note

User Contributed Notes 1 note

up
2
P S
1 year ago
These are the letters for the map:

R = red
G = green
B = blue
A = alpha (0 is transparent)
O = alpha (0 is opaque)
C = cyan
Y = yellow
M = magenta
K = black
I = intensity (for grayscale)
P = pad
To Top