PHP 8.4.1 Released!

Imagick::setImageMatte

(PECL imagick 2, PECL imagick 3)

Imagick::setImageMatteGörüntünün matlık kanalını ayarlar

Açıklama

public Imagick::setImageMatte(bool $matlık): bool

Görüntünün matlık kanalını ayarlar. Bu yöntem, derleme sırasında ImageMagick kütüphanesinin 6.2.9 veya sonraki bir sürümü kuruluysa kullanılabilir.

Bağımsız Değişkenler

matlık

true matlık kanalını etkin kılar, false iptal eder.

Dönen Değerler

Başarı durumunda true döner.

add a note

User Contributed Notes 1 note

up
4
martin at psinas dot com
13 years ago
I found this method is needed when creating a font / image mask, and needs to be set to false otherwise the mask won't take effect. Here is an example:

<?php

// Create objects
$image = new Imagick('myImage.png');
$watermark = new Imagick();
$mask = new Imagick();
$draw = new ImagickDraw();

// Define dimensions
$width = $image->getImageWidth();
$height = $image->getImageHeight();

// Create some palettes
$watermark->newImage($width, $height, new ImagickPixel('grey30'));
$mask->newImage($width, $height, new ImagickPixel('black'));

// Watermark text
$text = 'Copyright';

// Set font properties
$draw->setFont('Bookman-Demi');
$draw->setFontSize(20);
$draw->setFillColor('grey70');

// Position text
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);

// Draw text on the watermark palette
$watermark->annotateImage($draw, 10, 12, 0, $text);

// Draw text on the mask palette
$draw->setFillColor('white');
$mask->annotateImage($draw, 11, 13, 0, $text);
$mask->annotateImage($draw, 10, 12, 0, $text);
$draw->setFillColor('black');
$mask->annotateImage($draw, 9, 11, 0, $text);

// This is apparently needed for the mask to work
$mask->setImageMatte(false);

// Apply mask to watermark
$watermark->compositeImage($mask, Imagick::COMPOSITE_COPYOPACITY, 0, 0);

// Overlay watermark on image
$image->compositeImage($watermark, Imagick::COMPOSITE_DISSOLVE, 0, 0);

// Set output image format
$image->setImageFormat('png');

// Output the new image
header('Content-type: image/png');
echo
$image;

?>
To Top