/** * {@inheritdoc} */ public function chord(PointInterface $center, BoxInterface $size, $start, $end, ColorInterface $color, $fill = false, $thickness = 1) { $x = $center->getX(); $y = $center->getY(); $width = $size->getWidth(); $height = $size->getHeight(); try { $pixel = $this->getColor($color); $chord = new \ImagickDraw(); $chord->setStrokeColor($pixel); $chord->setStrokeWidth(max(1, (int) $thickness)); if ($fill) { $chord->setFillColor($pixel); } else { $this->line(new Point(round($x + $width / 2 * cos(deg2rad($start))), round($y + $height / 2 * sin(deg2rad($start)))), new Point(round($x + $width / 2 * cos(deg2rad($end))), round($y + $height / 2 * sin(deg2rad($end)))), $color); $chord->setFillColor('transparent'); } $chord->arc($x - $width / 2, $y - $height / 2, $x + $width / 2, $y + $height / 2, $start, $end); $this->imagick->drawImage($chord); $pixel->clear(); $pixel->destroy(); $chord->clear(); $chord->destroy(); } catch (\ImagickException $e) { throw new RuntimeException('Draw chord operation failed', $e->getCode(), $e); } return $this; }
function draw_pie(&$canvas, $ox, $oy, $r, $sd, $ed, $color) { $draw = new ImagickDraw(); $draw->setFillColor($color); $draw->setStrokeColor($color); $draw->setStrokeWidth(1); $draw->arc($ox - $r, $oy - $r, $ox + $r, $oy + $r, $sd, $ed); $draw->polygon(array(array('x' => $ox, 'y' => $oy), get_coord($ox, $oy, $r, $r, $sd), get_coord($ox, $oy, $r, $r, $ed))); $canvas->drawImage($draw); }
/** * 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); }
/** * Draw filled arc on current instance image * * @param string $stroke_color * @param string $fill_color * @param int $stroke_width * @param int $start_x * @param int $start_y * @param int $end_x * @param int $end_y * @param int $start_angle * @param int $end_angle * @param float $opacity * * @return image */ public function fillArc($stroke_color, $fill_color, $stroke_width, $start_x, $start_y, $end_x, $end_y, $start_angle = 0, $end_angle = 360, $opacity = 1) { $fill = new \ImagickDraw(); $fill->setStrokeWidth($stroke_width); $fill->setStrokeColor($stroke_color); $fill->setFillColor($fill_color); $fill->arc($start_x, $start_y, $end_x, $end_y, $start_angle, $end_angle); $this->imagick->drawimage($fill); return $this; }
/** * Draws an arc. * * @param integer $x The x coordinate of the centre. * @param integer $y The y coordinate of the centre. * @param integer $r The radius of the arc. * @param integer $start The start angle of the arc. * @param integer $end The end angle of the arc. * @param string $color The line color of the arc. * @param string $fill The fill color of the arc (defaults to none). */ public function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none') { $points = Horde_Image::arcPoints($r, $start, $end); $points['x1'] += $x; $points['x2'] += $x; $points['x3'] += $x; $points['y1'] += $y; $points['y2'] += $y; $points['y3'] += $y; try { $draw = new ImagickDraw(); $draw->setStrokeColor(new ImagickPixel($color)); $draw->setFillColor(new ImagickPixel($fill)); $draw->arc($x - $r, $y - $r, $x + $r, $y + $r, $start, $end); } catch (ImagickDrawException $e) { throw new Horde_Image_Exception($e); } catch (ImagickPixelException $e) { throw new Horde_Image_Exception($e); } // If filled, draw the outline. if (!empty($fill)) { $mid = round(($start + $end) / 2); list($x1, $y1) = Horde_Image::circlePoint($start, $r * 2); list($x2, $y2) = Horde_Image::circlePoint($mid, $r * 2); list($x3, $y3) = Horde_Image::circlePoint($end, $r * 2); $verts = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1))); if ($mid > 90) { $verts1 = array(array('x' => $x + round($x2), 'y' => $y + round($y2)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1))); $verts2 = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x2), 'y' => $y + round($y2))); $this->polygon($verts1, $fill, $fill); $this->polygon($verts2, $fill, $fill); } else { $this->polygon($verts, $fill, $fill); } $this->polyline($verts, $color); } try { $this->_imagick->drawImage($draw); } catch (ImagickException $e) { throw new Horde_Image_Exception($e); } $draw->destroy(); }
function arc($strokeColor, $fillColor, $backgroundColor, $startX, $startY, $endX, $endY, $startAngle, $endAngle) { //Create a ImagickDraw object to draw into. $draw = new \ImagickDraw(); $draw->setStrokeWidth(1); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $draw->setStrokeWidth(2); $draw->arc($startX, $startY, $endX, $endY, $startAngle, $endAngle); //Create an image object which the draw commands can be rendered into $image = new \Imagick(); $image->newImage(IMAGE_WIDTH, IMAGE_HEIGHT, $backgroundColor); $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(); }