PHP 8.3.4 Released!

Imagick::contrastImage

(PECL imagick 2, PECL imagick 3)

Imagick::contrastImageGörüntünün zıtlığını değiştirir

Açıklama

public Imagick::contrastImage(bool $zıtlık): bool

Görüntünün en koyu ve en açık pikselleri arasındaki yoğunluk farklarını ayarlar. netlik bağımsız değişkeninde sıfırdan farklı bir değer belirtilmesi zıtlığı arttırırken, tersi azaltır.

Bağımsız Değişkenler

zıklık

Zıtlık değeri.

Dönen Değerler

Başarı durumunda true döner.

Hatalar/İstisnalar

Hata durumunda bir ImagickException istisnası oluşur.

Örnekler

Örnek 1 - Imagick::contrastImage() örneği

<?php
function contrastImage($imagePath, $contrastType) {
$imagick = new \Imagick(realpath($imagePath));
if (
$contrastType != 2) {
$imagick->contrastImage($contrastType);
}

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

?>

add a note

User Contributed Notes 3 notes

up
3
removespam dot roland at tannerritchie dot com
9 years ago
Both xyking and quickshiftin include errors in their comments. xyking's error is in looping through negative numbers. quickshifting is incorrect in stating that 0 *increases* contrast (it does not - it decreases it).

Here is a (tested, working) method to increment or decrement contrast:
<?php
class Images {
public function
contrastImage($contrast, $imagePath){

$this->image = new Imagick();
$this->image->readImage($imagePath);

if (
$contrast > 0){
for (
$i = 1; $i < $contrast; $i++){
$this->image->contrastImage(1);
}
}else if (
$contrast <= 0) {

for (
$i = 0; $i > $contrast; $i--) {

$this->image->contrastImage(0);
}
}
}
}
?>
up
-4
xyking
13 years ago
Tip:
<?php
$image
->contrastImage(1); //Increase contrast once
$image->contrastImage(1); //Increase contrast more
$image->contrastImage(1); //Increase contrast even more

$image->contrastImage(0); //Decrease contrast once
$image->contrastImage(0); //Decrease contrast more
$image->contrastImage(0); //Decrease contrast even more

//This could be made into a function like this:
public function contrast($level) {
$level = (int)$level;
if (
$level < -10) {
$level = -10;
} else if (
$level > 10) {
$level = 10;
}
if (
$level > 0) {
for (
$i = 0; $i < $level; $i++) {
$this->image->contrastImage(1);
}
} else if (
$level < 0) {
for (
$i = $level; $i > 0; $i--) {
$this->image->contrastImage(0);
}
}
}
?>
up
-5
quickshiftin at gmail dot com
9 years ago
xyking's comment is wrong so be careful if you read it. You pass a value of 0 to *increase* the contrast.
To Top