我正在尝试使用Imagick生成一个随机图案,可以将其输出为两种颜色,即基础颜色和图案颜色。
<?php
function generateImage($base_color, $pattern_color)
{
// create the canvas
$canvas = new \Imagick();
$canvas->newPseudoImage(500, 500, 'plasma:fractal');
// threshold to convert to white and black
$canvas->thresholdImage(0.5 * \Imagick::getQuantum());
// blur
$canvas->blurImage(0, 1);
// base color
$canvas->setImageBackgroundColor($base_color);
$canvas->setImageAlphaChannel(\Imagick::ALPHACHANNEL_SHAPE);
// pattern color
// set format to png
$canvas->setImageFormat('png');
header('Content-Type: image/png');
echo $canvas->getImageBlob();
}
generateImage('#009990', '#cc4444');
我目前可以成功更改背景颜色,但是不确定如何更改图案。