参考文档: https://fengkui.net/articles/117
// 实现css
background: linear-gradient(-66deg, rgba(222,162,79,0.9) 0%, rgba(255,236,161,0.94) 39.74609375%, #DEA24F 100%);
public function drawPrice($priceText) { // 创建新的画布对象和透明底图像 $canvas = new \Imagick(); $canvas->newImage(720, 480, "none"); $text = '冯奎博客'; $text_color = '#000000'; $text_size = 80; // 创建新的imagick对象 $im = new \Imagick(); // 创建新图像。这将用作填充图案 $gradual_change = 100; $im->newPseudoImage($gradual_change, $gradual_change, "gradient:rgba(222,162,79,0.9)-rgba(255,236,161,0.94)-rgba(222,162,79,1)"); //$im->rotateimage("rgba(255, 255, 255, 0)", -60); // 创建imagickdraw对象 $draw = new \ImagickDraw(); // 开始一个叫做“渐变”的新模式 $draw->pushPattern('gradient', 0, 0, $gradual_change, $gradual_change); // 合成图案上的渐变 $draw->composite(\Imagick::COMPOSITE_OVER, 0, 0, $gradual_change, $gradual_change, $im); // 关闭模式 $draw->popPattern(); // 选择字体文件 $draw->setFont("./poster/Alibaba-PuHuiTi-Medium.otf"); // 使用称为“渐变”的图案作为填充 $draw->setFillPatternURL('#gradient'); // 设置字体大小 $draw->setFontSize($text_size); // 添加一些文本到画布上 $draw->annotation(30 + 250 + 30, 260, $text); // 将ImagickDraw绘制到画布上 $canvas->drawImage($draw); // 图像周围1个黑色边框 $canvas->borderImage('black', 1, 1); // 将格式设置为PNG $canvas->setImageFormat('png'); // 输出图像 // header("Content-Type: image/png"); return $canvas; }
标签:draw,gradual,渐变,canvas,imagick,rgba,text,php,change From: https://www.cnblogs.com/guiyishanren/p/17335451.html