(PECL imagick 2, PECL imagick 3)
ImagickPixel::__construct — ImagickPixel 构造函数
此函数目前没有文档;只有其参数列表可用。
构造一个 ImagickPixel 对象。如果指定了颜色,则在返回之前构造对象并用该颜色初始化对象。
color
用作此对象初始值的可选颜色字符串。
成功时返回 ImagickPixel 对象,失败时抛出 ImagickPixelException。
示例 #1 ImagickPixel::construct()
<?php
function construct() {
$columns = 4;
$exampleColors = array(
"rgba(100%, 0%, 0%, 0.5)",
"hsb(33.3333%, 100%, 75%)",
"hsl(120, 255, 191.25)",
"graya(50%, 0.5)",
"LightCoral", "none",
"#f00",
"#ff0000",
"#ff0000ff",
"#ffff00000000",
"#ffff00000000ffff",
"rgb(255, 0, 0)",
"rgb(100.0%, 0.0%, 0.0%)",
"rgb(255, 0, 0)",
"rgba(255, 0, 0, 1.0)",
"rgb(100%, 0%, 0%)",
"rgba(100%, 0%, 0%, 1.0)",
);
$draw = new \ImagickDraw();
$count = 0;
$black = new \ImagickPixel('rgb(0, 0, 0)');
foreach ($exampleColors as $exampleColor) {
$color = new \ImagickPixel($exampleColor);
$draw->setstrokewidth(1.0);
$draw->setStrokeColor($black);
$draw->setFillColor($color);
$offsetX = ($count % $columns) * 50 + 5;
$offsetY = intval($count / $columns) * 50 + 5;
$draw->rectangle(0 + $offsetX, 0 + $offsetY, 40 + $offsetX, 40 + $offsetY);
$count++;
}
$image = new \Imagick();
$image->newImage(350, 350, "blue");
$image->setImageFormat("png");
$image->drawImage($draw);
header("Content-Type: image/png");
echo $image->getImageBlob();
}
?>