public function histogram() { for ($i = 0; $i <= 256; $i++) { $this->data[$i] = array('r' => 0, 'g' => 0, 'b' => 0, 'y' => 0); } $this->iterate('hist_prepare'); $maxPixelCount = 0; foreach ($this->data as $k => $v) { $maxPixelCount = max($maxPixelCount, $v['r'], $v['g'], $v['b'], $v['y']); } $this->img->newImage(512, 512, new ImagickPixel('white')); $this->img->setImageFormat('png'); $draw = new ImagickDraw(); for ($i = 0; $i < 257; $i++) { $draw->setStrokeColor('#ff0000'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['r'] / $maxPixelCount * 512); $draw->setStrokeColor('#00ff00'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['g'] / $maxPixelCount * 512); $draw->setStrokeColor('#0000ff'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['b'] / $maxPixelCount * 512); $draw->setStrokeColor('#aaaaaa'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['y'] / $maxPixelCount * 512); } $this->img->drawImage($draw); }
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(); }
/** * 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); }
/** * 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); }
/** * @param ImageInterface $image * @return Image */ public function draw($image) { // Localize vars $width = $image->getWidth(); $height = $image->getHeight(); $imagick = $image->getCore(); $draw = new \ImagickDraw(); $strokeColor = new \ImagickPixel($this->getColor()->getHexString()); $fillColor = new \ImagickPixel('rgba(0,0,0,0)'); $draw->setStrokeOpacity(1); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); list($x1, $y1) = $this->point1; list($x2, $y2) = $this->control; list($x3, $y3) = $this->point2; $draw->pathStart(); $draw->pathMoveToAbsolute($x1, $y1); $draw->pathCurveToQuadraticBezierAbsolute($x2, $y2, $x3, $y3); $draw->pathFinish(); // Render the draw commands in the ImagickDraw object $imagick->drawImage($draw); $type = $image->getType(); $file = $image->getImageFile(); return new Image($imagick, $file, $width, $height, $type); // Create new image with updated core }
/** * 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); }
function __construct() { $draw = new ImagickDraw(); $draw->setFillColor('#B42AAF'); $draw->setStrokeColor('black'); $draw->setStrokeWidth(1); $this->draw = $draw; }
/** * @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; }
/** * 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; }
/** * 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); }
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; }
/** * @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 render() { $text = "Lorem ipsum"; $im = new \Imagick(); $draw = new \ImagickDraw(); $draw->setStrokeColor("none"); $draw->setFont("../fonts/Arial.ttf"); $draw->setFontSize(96); $draw->setTextAlignment(\Imagick::ALIGN_LEFT); $metrics = $im->queryFontMetrics($draw, $text); return print_table($metrics); }
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; }
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; }
/** * 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(); }
/** * @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; }
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); }
/** * 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; }
/** * 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; }
/** * 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; }
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(); }
/** * Draws an arc on the handle * * @param Zend_Image_Adapter_ImageMagick $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_DrawArc $arcObject) { $draw = new ImagickDraw(); $color = (string) $arcObject->getFillColor(); $draw->setStrokeColor($color); $location = $arcObject->getLocation($adapter); $cx = $location->getX(); $cy = $location->getY(); $width = $arcObject->getWidth(); $height = $arcObject->getHeight(); $sx = $cx - $width / 2; $ex = $cx + $width / 2; $sy = $cy - $height / 2; $ey = $cy + $height / 2; //$draw->arc($sx, $sy, $ex, $ey, $arcObject->getCutoutStart(), $arcObject->getCutoutEnd()); // $draw->arc($sx, $sy, $ex, $ey, 90, 315); $draw->arc($sx, $sy, $ex, $ey, 90, 270); $adapter->getHandle()->drawImage($draw); }
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; }
/** * @param ImageInterface $image * @return Image */ public function draw($image) { // Localize vars $width = $image->getWidth(); $height = $image->getHeight(); $imagick = $image->getCore(); $draw = new \ImagickDraw(); $strokeColor = new \ImagickPixel($this->getColor()->getHexString()); $fillColor = new \ImagickPixel('rgba(0,0,0,0)'); $draw->setStrokeOpacity(1); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $points = array(array('x' => $this->point1[0], 'y' => $this->point1[1]), array('x' => $this->control1[0], 'y' => $this->control1[1]), array('x' => $this->control2[0], 'y' => $this->control2[1]), array('x' => $this->point2[0], 'y' => $this->point2[1])); $draw->bezier($points); // Render the draw commands in the ImagickDraw object $imagick->drawImage($draw); $type = $image->getType(); $file = $image->getImageFile(); return new Image($imagick, $file, $width, $height, $type); // Create new image with updated core }
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(); }
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; }
/** * {@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; }