PHP Conference Japan 2024

Imagick::linearStretchImage

(PECL imagick 2,PECL imagick 3)

Imagick::linearStretchImage使用飽和度拉伸影像強度

描述

public Imagick::linearStretchImage(float $blackPoint, float $whitePoint): bool

使用飽和度拉伸影像強度。

參數

blackPoint

影像黑點

whitePoint

影像白點

回傳值

成功時回傳 true

範例

範例 #1 Imagick::linearStretchImage()

<?php
function linearStretchImage($imagePath, $blackThreshold, $whiteThreshold) {
$imagick = new \Imagick(realpath($imagePath));
$pixels = $imagick->getImageWidth() * $imagick->getImageHeight();
$imagick->linearStretchImage($blackThreshold * $pixels, $whiteThreshold * $pixels);

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

?>

新增附註

使用者貢獻的附註 1 則附註

1
SkepticaLee
10 年前
這裡的「黑點」和「白點」分別是從最暗和最亮端開始的像素計數。若要將最暗的 90% 像素轉為黑色,並將最亮的 5% 轉為白色,請使用以下程式碼

<?php
$im
= new Imagick ("some image.png");
list (
$width, $height) = array_values ($im->getImageGeometry ());
$px = $width * $height;
$im->modulateImage (100, 0, 100);
$im->linearStretchImage ($px * 0.9, $px * 0.05);
$im->writeImage ("temp.jpg");
?>
To Top