我想用黑色和一些不透明度来遮挡原始图像。想要使原始图像更暗一点。我使用编写此代码,但它不起作用:
$image = new Imagick("test.jpg");
$drawblacklayer = new ImagickDraw();
$drawblacklayer->setFillColor('black');
$drawblacklayer->setFillOpacity(0.8);
$coordinate = array( array( 'x' => 0, 'y' => 0 ), array( 'x' => 200, 'y' => 200 ) ); // seems need to use the original size of $image, but it's testing
$drawblacklayer->polygon($coordinate);
$image->drawImage($drawblacklayer);
header('Content-type: image/png');
echo $image;
答案 0 :(得分:1)
如果你期望一个黑暗的方格,你的$coordinate
数组将需要定义所有点。
$coordinate = array(
array( 'x' => 0, 'y' => 0 ), // Top-Left
array( 'x' => 200, 'y' => 0 ), // Top-Right
array( 'x' => 200, 'y' => 200 ), // Bottom-Right
array( 'x' => 0, 'y' => 200 ), // Bottom-Left
);
$drawblacklayer->polygon($coordinate);
或使用ImagickDraw::rectangle方法。
$drawblacklayer->rectangle( 0, 0, 200, 200 );