用imagemagick绘制多个圆圈

时间:2014-09-10 18:57:18

标签: php imagemagick

我正在尝试在背景图像上绘制多个圆圈,但我很难弄清楚如何去做。

我已尝试将多个imageMagick实例传递给绘图函数,但无法正常工作。

然后我尝试创建一个新的图像对象,并将其设置为透明。 然后我尝试在上面绘制一个图像,但我不能让它调整不透明度。

按照我想要做的是这样的: enter image description here

<?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);

    function drawImage(Imagick $im) {
    //    $im->setCompressionQuality(100);
          $im->setImageFormat("jpg");
          header("Content-Type: image/" . $im->getImageFormat());
          echo $im;
          exit;
    }

    // define circle mask
    $layer = new Imagick('spc.jpg');

    //now we need the height and width.
    $width = $layer->getImageWidth();
    $height = $layer->getImageHeight();
    $x = $width/2;
    $y = $height/2;

    $endX = $x + 150;
    $endY = $y + 150;

    $circle = new ImagickDraw();
    $circle->setFillColor("#FFFF00");
    $circle->circle($x, $y, $endX, $endY);
    //$layer->drawImage($circle, $circle2);

     $circle2 = new ImagickDraw();
     $circle2->setFillColor("#0000FF");
     $circle2->circle(0, 0, $x, $y);
     $layer->drawImage($circle, $circle2);

   drawImage($layer);
    ?>

2 个答案:

答案 0 :(得分:0)

drawImage shoud只获得1个参数。在最后几行试试这个:

$layer->drawImage($circle);
$layer->drawImage($circle2);
drawImage($layer);

答案 1 :(得分:0)

我认为/希望这更接近你的目标...我已经被攻击了一段时间因为我的环境与你的不同 - 但你应该能够看到我做了什么。

主要区别在于您需要将填充颜色设置为transparent,并将笔触颜色设置为您想要绘制圆形轮廓的任何颜色。此外,我重新使用了Draw对象而不是创建其他颜色每个圈子都有。

#!/usr/local/bin/php

<?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);

    function drawImage(Imagick $im) {
          $im->setImageFormat("jpg");
          $im->writeImage('out.jpg');
          exit;
    }

    // define circle mask
    $layer = new Imagick();
    $layer->newImage(500,250,new ImagickPixel('white'));
    $layer->borderImage('#6000ff',3,3);

    //now we need the height and width.
    $width = $layer->getImageWidth();
    $height = $layer->getImageHeight();
    $x = $width/2;
    $y = $height/2;

    $circle = new ImagickDraw();
    $circle->setFillColor('transparent'); // transparent
    $circle->setStrokeColor("#0000FF");   // blue
    $circle->circle($x, $y, $x + 25, $y);
    $layer->drawImage($circle);

    $circle->setStrokeColor("#00FF00");   // green
    $circle->circle($x, $y, $x + 50, $y);
    $layer->drawImage($circle);

    $circle->setStrokeColor("#FF00FF");   // purple
    $circle->circle($x, $y, $x +75, $y);
    $layer->drawImage($circle);

    $circle->setStrokeColor("#FF0000");   // red
    $circle->circle($x, $y, $x +100, $y);
    $layer->drawImage($circle);

    drawImage($layer);
?>

enter image description here