Beispiel #1
0
 public function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
Beispiel #2
0
 /**
  * Draws an ellipse on the handle
  *
  * @param ImageMagick-object $handle The handle on which the ellipse is drawn
  * @param Zend_Image_Action_DrawEllipse $ellipseObject The object that with all info
  */
 public function perform(Zend_Image_Adapter_ImageMagick $adapter, Zend_Image_Action_DrawEllipse $ellipseObject)
 {
     $draw = new ImagickDraw();
     $strokeColor = (string) $ellipseObject->getStrokeColor();
     $strokeAlpha = $ellipseObject->getStrokeAlpha() * 0.01;
     $draw->setStrokeColor($strokeColor);
     $draw->setStrokeOpacity($strokeAlpha);
     $draw->setStrokeWidth($ellipseObject->getStrokeWidth());
     $strokeDashArray = $ellipseObject->getStrokeDashPattern();
     if (count($strokeDashArray) > 0) {
         $draw->setStrokeDashArray($strokeDashArray);
     }
     $draw->setStrokeDashOffset($ellipseObject->getStrokeDashOffset());
     if ($ellipseObject->filled()) {
         $fillColor = (string) $ellipseObject->getFillColor();
         $draw->setFillColor($fillColor);
         $draw->setFillOpacity($ellipseObject->getFillAlpha() * 0.01);
     } else {
         $draw->setFillOpacity(0);
     }
     $width = $ellipseObject->getWidth();
     $height = $ellipseObject->getHeight();
     $x = $ellipseObject->getLocation()->getX();
     $y = $ellipseObject->getLocation()->getY();
     $draw->ellipse($x, $y, $width / 2, $height / 2, 0, 360);
     $adapter->getHandle()->drawImage($draw);
 }
Beispiel #3
0
    /**
     * Draws a polygon on the handle
     *
     * @param ImageMagick-object $handle The handle on which the polygon is drawn
     * @param Zend_Image_Action_DrawPolygon $polygon The object that with all info
     */
    public function perform($handle, Zend_Image_Action_DrawPolygon $polygon) { // As of ZF2.0 / PHP5.3, this can be made static.
        
        $points = $this->_parsePoints($polygon->getPoints());

        if ($polygon->isClosed()){
            //add first point at the end to close
            $points[count($points)] = $points[0];
        }

        $draw = new ImagickDraw();

        $draw->setStrokeColor('#' . $polygon->getStrokeColor()->getHex());

        $draw->setStrokeOpacity($polygon->getStrokeAlpha()/100);
        $draw->setStrokeWidth($polygon->getStrokeWidth());

        $strokeDashArray = $polygon->getStrokeDashPattern();
        if (count($strokeDashArray) > 0){
            $draw->setStrokeDashArray($strokeDashArray);
        }
        $draw->setStrokeDashOffset($polygon->getStrokeDashOffset());

        if($polygon->isFilled()) {
            $fillColor = $polygon->getFillColor();
            $draw->setFillColor('#' . $fillColor->getHex());
            $draw->polygon($points);

        } else {
            //Use transparent fill to render unfilled
            $draw->setFillOpacity(0);
            $draw->polyline($points);
        }

        $handle->getHandle()->drawImage($draw);
    }
 function __construct()
 {
     $draw = new ImagickDraw();
     $draw->setFillColor('#B42AAF');
     $draw->setStrokeColor('black');
     $draw->setStrokeWidth(1);
     $this->draw = $draw;
 }
 /**
  * Draw line between points
  * Нарисовать линии между указанными точками
  * @param int $sx
  * @param int $sy
  * @param int $ex
  * @param int $ey
  */
 public function drawLine($sx, $sy, $ex, $ey)
 {
     $draw = new \ImagickDraw();
     $draw->setStrokeColor($this->black);
     $draw->setStrokeWidth(1);
     $draw->line($sx, $sy, $ex, $ey);
     $this->drawImage($draw);
 }
Beispiel #6
0
 /**
  * @param \Imagick $imagick
  * @param int $graphWidth
  * @param int $graphHeight
  */
 public static function analyzeImage(\Imagick $imagick, $graphWidth = 255, $graphHeight = 127)
 {
     $sampleHeight = 20;
     $border = 2;
     $imagick->transposeImage();
     $imagick->scaleImage($graphWidth, $sampleHeight);
     $imageIterator = new \ImagickPixelIterator($imagick);
     $luminosityArray = [];
     foreach ($imageIterator as $row => $pixels) {
         /* Loop through pixel rows */
         foreach ($pixels as $column => $pixel) {
             /* Loop through the pixels in the row (columns) */
             /** @var $pixel \ImagickPixel */
             if (false) {
                 $color = $pixel->getColor();
                 $luminosityArray[] = $color['r'];
             } else {
                 $hsl = $pixel->getHSL();
                 $luminosityArray[] = $hsl['luminosity'];
             }
         }
         /* Sync the iterator, this is important to do on each iteration */
         $imageIterator->syncIterator();
         break;
     }
     $draw = new \ImagickDraw();
     $strokeColor = new \ImagickPixel('red');
     $fillColor = new \ImagickPixel('red');
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $draw->setStrokeWidth(0);
     $draw->setFontSize(72);
     $draw->setStrokeAntiAlias(true);
     $previous = false;
     $x = 0;
     foreach ($luminosityArray as $luminosity) {
         $pos = $graphHeight - 1 - $luminosity * ($graphHeight - 1);
         if ($previous !== false) {
             /** @var $previous int */
             //printf ( "%d, %d, %d, %d <br/>\n" , $x - 1, $previous, $x, $pos);
             $draw->line($x - 1, $previous, $x, $pos);
         }
         $x += 1;
         $previous = $pos;
     }
     $plot = new \Imagick();
     $plot->newImage($graphWidth, $graphHeight, 'white');
     $plot->drawImage($draw);
     $outputImage = new \Imagick();
     $outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
     $outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
     $outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
     $outputImage->borderimage('black', $border, $border);
     $outputImage->setImageFormat("png");
     App::cachingHeader("Content-Type: image/png");
     echo $outputImage;
 }
Beispiel #7
0
 /**
  * Draw current instance of line to given endpoint on given image
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $line = new \ImagickDraw();
     $color = new Color($this->color);
     $line->setStrokeColor($color->getPixel());
     $line->setStrokeWidth($this->width);
     $line->line($this->x, $this->y, $x, $y);
     $image->getCore()->drawImage($line);
     return true;
 }
Beispiel #8
0
 /**
  * Draw a line on the image, returns the GD-handle
  *
  * @param  Zend_Image_Adapter_ImageMagick image resource    $handle Image to work on
  * @param  Zend_Image_Action_DrawLine   $lineObject The object containing all settings needed for drawing a line.
  * @return void
  */
 public function perform(Zend_Image_Adapter_ImageMagick $adapter, Zend_Image_Action_DrawLine $lineObject)
 {
     $handle = $adapter->getHandle();
     $draw = new ImagickDraw();
     $draw->setStrokeWidth($lineObject->getStrokeWidth());
     $color = $lineObject->getStrokeColor();
     $draw->setStrokeColor((string) $color);
     $draw->setStrokeOpacity($lineObject->getStrokeAlpha());
     $draw->line($lineObject->getPointStart()->getX(), $lineObject->getPointStart()->getY(), $lineObject->getPointEnd()->getX(), $lineObject->getPointEnd()->getY());
     $handle->drawImage($draw);
 }
Beispiel #9
0
 public function getDraw()
 {
     $draw = new \ImagickDraw();
     $strokeColor = new \ImagickPixel($this->strokeColor);
     $fillColor = new \ImagickPixel($this->fillColor);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $draw->setStrokeWidth(2);
     return $draw;
 }
Beispiel #10
0
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function draw($image)
 {
     $strokeColor = new \ImagickPixel($this->getColor()->getHexString());
     $draw = new \ImagickDraw();
     $draw->setStrokeColor($strokeColor);
     $draw->setStrokeWidth($this->thickness);
     list($x1, $y1) = $this->point1;
     list($x2, $y2) = $this->point2;
     $draw->line($x1, $y1, $x2, $y2);
     $image->getCore()->drawImage($draw);
     return $image;
 }
function drawText(\Imagick $imagick, $shadow = false)
{
    $draw = new \ImagickDraw();
    if ($shadow == true) {
        $draw->setStrokeColor('black');
        $draw->setStrokeWidth(8);
        $draw->setFillColor('black');
    } else {
        $draw->setStrokeColor('none');
        $draw->setStrokeWidth(1);
        $draw->setFillColor('lightblue');
    }
    $draw->setFontSize(96);
    $text = "Imagick\nExample";
    $draw->setFont("../fonts/CANDY.TTF");
    $draw->setGravity(\Imagick::GRAVITY_SOUTHWEST);
    $imagick->annotateimage($draw, 40, 40, 0, $text);
    if ($shadow == true) {
        $imagick->blurImage(10, 5);
    }
    return $imagick;
}
Beispiel #12
0
 public function build()
 {
     // Prepage image
     $this->_canvas = new Imagick();
     $this->_canvas->newImage(self::WIDTH, self::HEIGHT, new ImagickPixel("white"));
     $color['line'] = new ImagickPixel("rgb(216, 76, 64)");
     $color['text'] = new ImagickPixel("rgb(16, 35, 132)");
     $color['karma'] = new ImagickPixel("rgb(116, 194, 98)");
     $color['force'] = new ImagickPixel("rgb(37, 168, 255)");
     $color['bottom_bg'] = new ImagickPixel("rgb(255, 244, 224)");
     $color['bg'] = new ImagickPixel("white");
     $color['neutral'] = new ImagickPixel("rgb(200, 200, 200)");
     $color['habr'] = new ImagickPixel("rgb(83, 121, 139)");
     $color['transparent'] = new ImagickPixel("transparent");
     // Prepare canvas for drawing main graph
     $draw = new ImagickDraw();
     $draw->setStrokeAntialias(true);
     $draw->setStrokeWidth(2);
     // Draw bottom bg
     define('TOP_SPACER', 10);
     $draw = new ImagickDraw();
     $draw->setFillColor($color['bg']);
     $draw->setStrokeColor($color['habr']);
     $draw->polyline(array(array('x' => 0, 'y' => 0), array('x' => self::WIDTH - 1, 'y' => 0), array('x' => self::WIDTH - 1, 'y' => self::HEIGHT - 1), array('x' => 0, 'y' => self::HEIGHT - 1), array('x' => 0, 'y' => 0)));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     // Draw texts
     $draw = new ImagickDraw();
     $draw->setTextAlignment(Imagick::ALIGN_CENTER);
     $draw->setTextAntialias(true);
     $draw->setFont(realpath('stuff/consola.ttf'));
     $draw->setFontSize(10);
     $draw->setFillColor($color['neutral']);
     $draw->annotation(self::WIDTH / 2, 26, "рейтинг: " . $this->_rate);
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     $draw = new ImagickDraw();
     $draw->setTextAlignment(Imagick::ALIGN_CENTER);
     $draw->setTextAntialias(true);
     $draw->setTextUnderColor($color['karma']);
     $draw->setFillColor($color['bg']);
     $draw->setFontSize(12);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->annotation(self::WIDTH / 4 + 1, 12, sprintf('%01.2f', $this->_karma));
     $draw->setTextUnderColor($color['force']);
     $draw->setFillColor($color['bg']);
     $draw->annotation(self::WIDTH / 4 * 3 - 1, 12, sprintf('%01.2f', $this->_habraforce));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     return true;
 }
Beispiel #13
0
 /**
  * Add border
  * @param integer $width Border width
  * @param string $color Border color
  * @return Imagick
  */
 public function border($width, $color)
 {
     $border = new \ImagickDraw();
     $border->setFillColor('none');
     $border->setStrokeColor(new \ImagickPixel($color));
     $border->setStrokeWidth($width);
     $widthPart = $width / 2;
     $border->line(0, 0 + $widthPart, $this->width, 0 + $widthPart);
     $border->line(0, $this->height - $widthPart, $this->width, $this->height - $widthPart);
     $border->line(0 + $widthPart, 0, 0 + $widthPart, $this->height);
     $border->line($this->width - $widthPart, 0, $this->width - $widthPart, $this->height);
     $this->image->drawImage($border);
     return $this;
 }
 function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     //        $compositeModes = [
     //
     //            \Imagick::COMPOSITE_NO, \Imagick::COMPOSITE_ADD, \Imagick::COMPOSITE_ATOP, \Imagick::COMPOSITE_BLEND, \Imagick::COMPOSITE_BUMPMAP, \Imagick::COMPOSITE_CLEAR, \Imagick::COMPOSITE_COLORBURN, \Imagick::COMPOSITE_COLORDODGE, \Imagick::COMPOSITE_COLORIZE, \Imagick::COMPOSITE_COPYBLACK, \Imagick::COMPOSITE_COPYBLUE, \Imagick::COMPOSITE_COPY, \Imagick::COMPOSITE_COPYCYAN, \Imagick::COMPOSITE_COPYGREEN, \Imagick::COMPOSITE_COPYMAGENTA, \Imagick::COMPOSITE_COPYOPACITY, \Imagick::COMPOSITE_COPYRED, \Imagick::COMPOSITE_COPYYELLOW, \Imagick::COMPOSITE_DARKEN, \Imagick::COMPOSITE_DSTATOP, \Imagick::COMPOSITE_DST, \Imagick::COMPOSITE_DSTIN, \Imagick::COMPOSITE_DSTOUT, \Imagick::COMPOSITE_DSTOVER, \Imagick::COMPOSITE_DIFFERENCE, \Imagick::COMPOSITE_DISPLACE, \Imagick::COMPOSITE_DISSOLVE, \Imagick::COMPOSITE_EXCLUSION, \Imagick::COMPOSITE_HARDLIGHT, \Imagick::COMPOSITE_HUE, \Imagick::COMPOSITE_IN, \Imagick::COMPOSITE_LIGHTEN, \Imagick::COMPOSITE_LUMINIZE, \Imagick::COMPOSITE_MINUS, \Imagick::COMPOSITE_MODULATE, \Imagick::COMPOSITE_MULTIPLY, \Imagick::COMPOSITE_OUT, \Imagick::COMPOSITE_OVER, \Imagick::COMPOSITE_OVERLAY, \Imagick::COMPOSITE_PLUS, \Imagick::COMPOSITE_REPLACE, \Imagick::COMPOSITE_SATURATE, \Imagick::COMPOSITE_SCREEN, \Imagick::COMPOSITE_SOFTLIGHT, \Imagick::COMPOSITE_SRCATOP, \Imagick::COMPOSITE_SRC, \Imagick::COMPOSITE_SRCIN, \Imagick::COMPOSITE_SRCOUT, \Imagick::COMPOSITE_SRCOVER, \Imagick::COMPOSITE_SUBTRACT, \Imagick::COMPOSITE_THRESHOLD, \Imagick::COMPOSITE_XOR,
     //
     //        ];
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
Beispiel #15
0
function test_shape(&$canvas)
{
    $draw = new ImagickDraw();
    $draw->setFillColor('transparent');
    $draw->setStrokeColor('#F02B88');
    $draw->setStrokeWidth(9);
    $draw->translate(200, 100);
    $draw->rectangle(-50, -50, 50, 50);
    $draw->translate(200, 100);
    $draw->ellipse(0, 0, 100, 80, 0, 360);
    $draw->skewX(-30);
    $draw->translate(200, 100);
    $draw->circle(0, 0, 50, 50);
    $canvas->drawImage($draw);
}
Beispiel #16
0
 /**
  * @param ImageInterface $image
  * @return ImageInterface
  */
 public function draw($image)
 {
     $strokeColor = new \ImagickPixel($this->getBorderColor()->getHexString());
     $fillColor = new \ImagickPixel($this->getFillColor()->getHexString());
     $draw = new \ImagickDraw();
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $draw->setStrokeWidth($this->borderSize);
     list($x, $y) = $this->pos;
     $left = $x + $this->width / 2;
     $top = $y + $this->height / 2;
     $draw->ellipse($left, $top, $this->width / 2, $this->height / 2, 0, 360);
     $image->getCore()->drawImage($draw);
     return $image;
 }
Beispiel #17
0
 /**
  * Draw rectangle to given image at certain position
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $rectangle = new \ImagickDraw();
     // set background
     $bgcolor = new Color($this->background);
     $rectangle->setFillColor($bgcolor->getPixel());
     // set border
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         $rectangle->setStrokeWidth($this->border_width);
         $rectangle->setStrokeColor($border_color->getPixel());
     }
     $rectangle->rectangle($this->x1, $this->y1, $this->x2, $this->y2);
     $image->getCore()->drawImage($rectangle);
     return true;
 }
Beispiel #18
0
 /**
  * Draw polygon on given image
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $polygon = new \ImagickDraw();
     // set background
     $bgcolor = new Color($this->background);
     $polygon->setFillColor($bgcolor->getPixel());
     // set border
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         $polygon->setStrokeWidth($this->border_width);
         $polygon->setStrokeColor($border_color->getPixel());
     }
     $polygon->polygon($this->points);
     $image->getCore()->drawImage($polygon);
     return true;
 }
Beispiel #19
0
 /**
  * Draw ellipse instance on given image
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $circle = new \ImagickDraw();
     // set background
     $bgcolor = new Color($this->background);
     $circle->setFillColor($bgcolor->getPixel());
     // set border
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         $circle->setStrokeWidth($this->border_width);
         $circle->setStrokeColor($border_color->getPixel());
     }
     $circle->ellipse($x, $y, $this->width / 2, $this->height / 2, 0, 360);
     $image->getCore()->drawImage($circle);
     return true;
 }
Beispiel #20
0
 function renderImage3()
 {
     //dupe of two ?
     $draw = new \ImagickDraw();
     $strokeColor = new \ImagickPixel($this->strokeColor);
     $fillColor = new \ImagickPixel($this->fillColor);
     $draw->setStrokeWidth(1);
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $fillRules = [\Imagick::FILLRULE_NONZERO, \Imagick::FILLRULE_EVENODD];
     $points = 11;
     $size = 150;
     $draw->translate(175, 160);
     for ($x = 0; $x < 2; $x++) {
         //$pointsArray = array();
         $draw->setFillRule($fillRules[$x]);
         $draw->pathStart();
         for ($n = 0; $n < $points * 2; $n++) {
             if ($n >= $points) {
                 $angle = fmod($n * 360 * 4 / $points, 360) * pi() / 180;
             } else {
                 $angle = fmod($n * 360 * 3 / $points, 360) * pi() / 180;
             }
             $positionX = $size * sin($angle);
             $positionY = $size * cos($angle);
             if ($n == 0) {
                 $draw->pathMoveToAbsolute($positionX, $positionY);
             } else {
                 $draw->pathLineToAbsolute($positionX, $positionY);
             }
         }
         $draw->pathClose();
         $draw->pathFinish();
         $draw->translate(325, 0);
     }
     //Create an image object which the draw commands can be rendered into
     $image = new \Imagick();
     //$image->newImage(700, 320, $this->backgroundColor);
     $image->newImage(700, 320, "#eee");
     $image->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $image->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $image->getImageBlob();
 }
Beispiel #21
0
function getImageHistogram($imagePath)
{
    $backgroundColor = 'black';
    $draw = new \ImagickDraw();
    $draw->setStrokeWidth(0);
    //make the lines be as thin as possible
    $imagick = new \Imagick();
    $imagick->newImage(500, 500, $backgroundColor);
    $imagick->setImageFormat("png");
    $imagick->drawImage($draw);
    $histogramWidth = 256;
    $histogramHeight = 100;
    // the height for each RGB segment
    $imagick = new \Imagick(realpath($imagePath));
    //Resize the image to be small, otherwise PHP tends to run out of memory
    //This might lead to bad results for images that are pathologically 'pixelly'
    $imagick->adaptiveResizeImage(200, 200, true);
    $histogramElements = $imagick->getImageHistogram();
    $histogram = new \Imagick();
    $histogram->newpseudoimage($histogramWidth, $histogramHeight * 3, 'xc:black');
    $histogram->setImageFormat('png');
    $getMax = function ($carry, $item) {
        if ($item > $carry) {
            return $item;
        }
        return $carry;
    };
    $colorValues = ['red' => getColorStatistics($histogramElements, \Imagick::COLOR_RED), 'lime' => getColorStatistics($histogramElements, \Imagick::COLOR_GREEN), 'blue' => getColorStatistics($histogramElements, \Imagick::COLOR_BLUE)];
    $max = array_reduce($colorValues['red'], $getMax, 0);
    $max = array_reduce($colorValues['lime'], $getMax, $max);
    $max = array_reduce($colorValues['blue'], $getMax, $max);
    $scale = $histogramHeight / $max;
    $count = 0;
    foreach ($colorValues as $color => $values) {
        $draw->setstrokecolor($color);
        $offset = ($count + 1) * $histogramHeight;
        foreach ($values as $index => $value) {
            $draw->line($index, $offset, $index, $offset - $value * $scale);
        }
        $count++;
    }
    $histogram->drawImage($draw);
    header("Content-Type: image/png");
    echo $histogram;
}
Beispiel #22
0
 public function draw($image)
 {
     $draw = new \ImagickDraw();
     $draw->setStrokeWidth($this->borderSize);
     if (null !== $this->fillColor) {
         $fillColor = new \ImagickPixel($this->fillColor->getHexString());
         $draw->setFillColor($fillColor);
     } else {
         $draw->setFillOpacity(0);
     }
     if (null !== $this->borderColor) {
         $borderColor = new \ImagickPixel($this->borderColor->getHexString());
         $draw->setStrokeColor($borderColor);
     } else {
         $draw->setStrokeOpacity(0);
     }
     $draw->polygon($this->points());
     $image->getCore()->drawImage($draw);
     return $image;
 }
Beispiel #23
0
 public function renderImage()
 {
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     $lightColor = new \ImagickPixel('LightCoral');
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor($lightColor);
     $draw->setStrokeWidth(2);
     $draw->setFontSize(36);
     $draw->setFont("../fonts/Arial.ttf");
     $draw->annotation(50, 50, "Lorem Ipsum!");
     $msg = "Danack";
     $xpos = 0;
     $ypos = 0;
     list($lines, $lineHeight) = wordWrapAnnotation($imagick, $draw, $msg, 140);
     for ($i = 0; $i < count($lines); $i++) {
         $imagick->annotateImage($draw, $xpos, $ypos + $i * $lineHeight, 0, $lines[$i]);
     }
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
 }
function makeSimpleGif($deconstruct)
{
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $circleRadius = 20;
    $imageFrames = 40;
    $imageSize = 200;
    $background = new \Imagick();
    $background->newpseudoimage($imageSize, $imageSize, "plasma:tomato-steelblue");
    $blackWhite = new \Imagick();
    $blackWhite->newpseudoimage($imageSize, $imageSize, "gradient:black-white");
    $backgroundPalette = clone $background;
    $backgroundPalette->quantizeImage(240, \Imagick::COLORSPACE_RGB, 8, false, false);
    $blackWhitePalette = clone $blackWhite;
    $blackWhitePalette->quantizeImage(16, \Imagick::COLORSPACE_RGB, 8, false, false);
    $backgroundPalette->addimage($blackWhitePalette);
    for ($count = 0; $count < $imageFrames; $count++) {
        $drawing = new \ImagickDraw();
        $drawing->setFillColor('white');
        $drawing->setStrokeColor('rgba(64, 64, 64, 0.8)');
        $strokeWidth = 4;
        $drawing->setStrokeWidth($strokeWidth);
        $distanceToMove = $imageSize + ($circleRadius + $strokeWidth) * 2;
        $offset = $distanceToMove * $count / ($imageFrames - 1) - ($circleRadius + $strokeWidth);
        $drawing->translate($offset, $imageSize / 2 + $imageSize / 3 * cos(20 * $count / $imageFrames));
        $drawing->circle(0, 0, $circleRadius, 0);
        $frame = clone $background;
        $frame->drawimage($drawing);
        $frame->clutimage($backgroundPalette);
        $frame->setImageDelay(10);
        $aniGif->addImage($frame);
    }
    if ($deconstruct == true) {
        $aniGif = $aniGif->deconstructImages();
    }
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}
Beispiel #25
0
 public function draw($image)
 {
     $draw = new \ImagickDraw();
     $draw->setStrokeWidth($this->borderSize);
     if (null !== $this->fillColor) {
         $fillColor = new \ImagickPixel($this->fillColor->getHexString());
         $draw->setFillColor($fillColor);
     } else {
         $draw->setFillOpacity(0);
     }
     if (null !== $this->borderColor) {
         $borderColor = new \ImagickPixel($this->borderColor->getHexString());
         $draw->setStrokeColor($borderColor);
     } else {
         $draw->setStrokeOpacity(0);
     }
     $x1 = $this->pos[0];
     $x2 = $x1 + $this->getWidth();
     $y1 = $this->pos[1];
     $y2 = $y1 + $this->getHeight();
     $draw->rectangle($x1, $y1, $x2, $y2);
     $image->getCore()->drawImage($draw);
     return $image;
 }
Beispiel #26
0
 /**
  * {@inheritdoc}
  */
 public function polygon(array $coordinates, ColorInterface $color, $fill = false, $thickness = 1)
 {
     if (count($coordinates) < 3) {
         throw new InvalidArgumentException(sprintf('Polygon must consist of at least 3 coordinates, %d given', count($coordinates)));
     }
     $points = array_map(function (PointInterface $p) {
         return array('x' => $p->getX(), 'y' => $p->getY());
     }, $coordinates);
     try {
         $pixel = $this->getColor($color);
         $polygon = new \ImagickDraw();
         $polygon->setStrokeColor($pixel);
         $polygon->setStrokeWidth(max(1, (int) $thickness));
         if ($fill) {
             $polygon->setFillColor($pixel);
         } else {
             $polygon->setFillColor('transparent');
         }
         $polygon->polygon($points);
         $this->imagick->drawImage($polygon);
         $pixel->clear();
         $pixel->destroy();
         $polygon->clear();
         $polygon->destroy();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Draw polygon operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Beispiel #27
0
$scaleLineTop->drawImage($draw);
$canvas->compositeImage($scaleLineTop, imagick::COMPOSITE_OVER, $w - ($scaleLineWidth + 15) - $compassImg->getImageWidth(), $h - ($scaleLineHeight * 2 + 15));
// bottom
$scaleLineBottom = new Imagick();
$scaleLineBottom->newImage($scaleLineBottomWidth, $scaleLineHeight, new ImagickPixel('white'));
$scaleLineBottom->setImageFormat('png');
$draw = new ImagickDraw();
$draw->setFont('Helvetica');
$draw->setFontSize(12);
$draw->setGravity(imagick::GRAVITY_CENTER);
$draw->annotation(0, 0, $json->{'scaleLineBottom'}->{'val'});
$scaleLineBottom->drawImage($draw);
$scaleLineBottom->borderImage('black', $lineWidth, $lineWidth);
$draw = new ImagickDraw();
$draw->setStrokeColor(new ImagickPixel('white'));
$draw->setStrokeWidth($lineWidth * 2);
$draw->line(0, $scaleLineHeight + 2, $scaleLineBottomWidth + $lineWidth * 2, $scaleLineHeight + 2);
$scaleLineBottom->drawImage($draw);
$canvas->compositeImage($scaleLineBottom, imagick::COMPOSITE_OVER, $w - ($scaleLineWidth + 15) - $compassImg->getImageWidth(), $h - ($scaleLineHeight + 15 - $lineWidth));
$canvas->writeImage($tmp_dir . $id . '.png');
$canvas = new Imagick();
$canvas->newImage($legSize[0], $legSize[1], new ImagickPixel('white'));
$canvas->setImageFormat('png');
$runningHt = 15;
for ($i = count($legends) - 1; $i >= 0; $i--) {
    $p = explode("\n", $titles[$i]);
    $draw = new ImagickDraw();
    $draw->setFont('Helvetica');
    $draw->setFontSize(12);
    $draw->annotation(5, $runningHt, $titles[$i]);
    $canvas->drawImage($draw);
 /**
  * 在图片上划线
  * @param  object  $image             Imagick的实例
  * @param  integer $num               画线的数量
  * @return object  Imagick的实例
  */
 protected function imagickLine($image, $num = 4)
 {
     $draw = new \ImagickDraw();
     for ($i = 0; $i < $num; $i++) {
         $color = $this->randColor();
         $startx = rand(0, $this->width);
         $endx = rand(0, $this->width);
         $starty = rand(0, $this->height);
         $endy = rand(0, $this->height);
         $draw->setStrokeColor($color);
         $draw->setFillColor($color);
         $draw->setStrokeWidth(2);
         $draw->line($startx, $starty, $endx, $endy);
     }
     $image->drawImage($draw);
     $draw->destroy();
     return $image;
 }
Beispiel #29
0
 /**
  * Draw a polygon on the image.
  *
  * @param  array $points
  * @return Imagick
  */
 public function polygon($points)
 {
     $draw = new \ImagickDraw();
     if (null !== $this->fillColor) {
         $draw->setFillColor($this->image->getColor($this->fillColor, $this->opacity));
     }
     if ($this->strokeWidth > 0) {
         $draw->setStrokeColor($this->image->getColor($this->strokeColor, $this->opacity));
         $draw->setStrokeWidth($this->strokeWidth);
     }
     $draw->polygon($points);
     $this->image->resource()->drawImage($draw);
     return $this;
 }
Beispiel #30
0
function psychedelicFontGif($name = 'Danack')
{
    set_time_limit(3000);
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $maxFrames = 11;
    $scale = 0.25;
    for ($frame = 0; $frame < $maxFrames; $frame++) {
        $draw = new \ImagickDraw();
        $draw->setStrokeOpacity(1);
        $draw->setFont("../fonts/CANDY.TTF");
        $draw->setfontsize(150 * $scale);
        for ($strokeWidth = 25; $strokeWidth > 0; $strokeWidth--) {
            $hue = intval(fmod($frame * 360 / $maxFrames + 170 + $strokeWidth * 360 / 25, 360));
            $color = "hsl({$hue}, 255, 128)";
            $draw->setStrokeColor($color);
            $draw->setFillColor($color);
            $draw->setStrokeWidth($strokeWidth * 3 * $scale);
            $draw->annotation(60 * $scale, 165 * $scale, $name);
        }
        $draw->setStrokeColor('none');
        $draw->setFillColor('black');
        $draw->setStrokeWidth(0);
        $draw->annotation(60 * $scale, 165 * $scale, $name);
        //Create an image object which the draw commands can be rendered into
        $imagick = new \Imagick();
        $imagick->newImage(650 * $scale, 230 * $scale, "#eee");
        $imagick->setImageFormat("png");
        //Render the draw commands in the ImagickDraw object
        //into the image.
        $imagick->drawImage($draw);
        $imagick->setImageDelay(5);
        $aniGif->addImage($imagick);
        $imagick->destroy();
    }
    $aniGif->setImageIterations(0);
    //loop forever
    $aniGif->deconstructImages();
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}