PHP 8.5.4 Released!

Imagick::colorMatrixImage

(PECL imagick 3 >= 3.3.0)

Imagick::colorMatrixImage画像に色変換を適用する

説明

public Imagick::colorMatrixImage(array $color_matrix): bool

画像に色変換を適用します。 このメソッドは、彩度の変更、色相の回転、輝度からアルファへの変換、 その他さまざまな効果を実現できます。 可変サイズの変換行列を使うこともできますが、 通常は RGBA 画像には 5x5 の行列を、CMYKA(またはオフセット付きの RGBA) には 6x6 の行列を使います。 この行列は Adobe Flash で使われるものと似ていますが、 オフセットが 5 列目ではなく 6 列目にあり(CMYKA 画像をサポートするため)、 オフセットは正規化されています(Flash のオフセットを 255 で除算します)。

パラメータ

color_matrix

戻り値

成功した場合に true を返します。

例1 Imagick::colorMatrixImage()

<?php
function colorMatrixImage($imagePath, $colorMatrix) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->setImageOpacity(1);

//色変換行列は以下のようになります:
// $colorMatrix = [
// 1.5, 0.0, 0.0, 0.0, 0.0, -0.157,
// 0.0, 1.0, 0.5, 0.0, 0.0, -0.157,
// 0.0, 0.0, 1.5, 0.0, 0.0, -0.157,
// 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
// 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
// 0.0, 0.0, 0.0, 0.0, 0.0, 1.0
// ];

$background = new \Imagick();
$background->newPseudoImage($imagick->getImageWidth(), $imagick->getImageHeight(), "pattern:checkerboard");

$background->setImageFormat('png');

$imagick->setImageFormat('png');
$imagick->colorMatrixImage($colorMatrix);

$background->compositeImage($imagick, \Imagick::COMPOSITE_ATOP, 0, 0);

header("Content-Type: image/png");
echo
$background->getImageBlob();
}

?>

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top