CakeFest 2024: The Official CakePHP Conference

ImagickPixel::setHSL

(PECL imagick 2, PECL imagick 3)

ImagickPixel::setHSL正規化した HSL カラーを設定する

説明

public ImagickPixel::setHSL(float $hue, float $saturation, float $luminosity): bool

hue (色相)、saturation (彩度) および luminosity (明度) を正規化した値によって ImagickPixel オブジェクトの色を設定します。

パラメータ

hue

色相を正規化した値。これは、色相環上での位置 (0 から 1 まで) を表します。ゼロは赤です。

saturation

彩度を正規化した値。1 が最大です。

luminosity

明度を正規化した値。黒が 0、白が 1 で、 0.5 にすると完全な HS 値が再現されます。

戻り値

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

例1 ImagickPixel::setHSL() による色の変更

<?php

// ほぼ真っ赤な色を作ります
$color = new ImagickPixel('rgb(90%, 10%, 10%)');

// その HSL 値を取得します
$colorInfo = $color->getHSL();

// 色相を 180 度反転させます
$newHue = $colorInfo['hue'] + 0.5;
if (
$newHue > 1) {
$newHue = $newHue - 1;
}

// ImagickPixel を新しい色に設定します
$colorInfo = $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']);

// 新しい色が青/緑になることを確かめます
$colorInfo = $color->getcolor();
print_r($colorInfo);

?>

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

Array
(
    [r] => 26
    [g] => 230
    [b] => 230
    [a] => 255
)

注意

注意:

ImageMagick ライブラリバージョン 6.2.9 以降で使用可能です。

add a note

User Contributed Notes

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