php教程

ImagickDraw::arc

(PECL imagick 2.0.0)

ImagickDraw::arcDraws an arc

说明

ImagickDraw::arc ( float $sx , float $sy , float $ex , float $ey , float $sd , float $ed ) : bool
Warning

本函数还未编写文档,仅有参数列表。

Draws an arc falling within a specified bounding rectangle on the image.

参数

sx

Starting x ordinate of bounding rectangle

sy

starting y ordinate of bounding rectangle

ex

ending x ordinate of bounding rectangle

ey

ending y ordinate of bounding rectangle

sd

starting degrees of rotation

ed

ending degrees of rotation

返回值

没有返回值。

范例

Example #1 ImagickDraw::arc()

<?php
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_WIDTHIMAGE_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();
}

?>

User Contributed Notes

skmanji at manji dot org 24-Jun-2011 06:30
You can do a pie chart with a combination of arc and polygon functions (there really ought to be a built-in command for this)

<?php
//  create a new canvas object and a white image
$canvas     = new Imagick();
$canvas->newImage(600, 600, 'grey');

image_pie($canvas, 300, 300, 200, 0, 45, 'red');
image_pie($canvas, 300, 300, 200, 45, 125, 'green');
image_pie($canvas, 300, 300, 200, 125, 225, 'blue');
image_pie($canvas, 300, 300, 200, 225, 300, 'cyan');
image_pie($canvas, 300, 300, 200, 300, 360, 'orange');

//  output the image
$canvas->setImageFormat('png');
header("Content-Type: image/png");
echo
$canvas;
exit;

// FUNCTIONS

function image_arc( &$canvas, $sx, $sy, $ex, $ey, $sd, $ed, $color = 'black' ) {

   
//  draw arc on canvas
    //  $sx, $sy, $ex, $ey specify a bounding rectangle of a circle with the origin in the middle
    //  $sd, and $ed specify start and end angles in degrees

   
$draw = new ImagickDraw();
   
$draw->setFillColor($color);
   
$draw->setStrokeColor($color);
   
$draw->setStrokeWidth(1);
   
$draw->arc($sx, $sy, $ex, $ey, $sd, $ed);
   
$canvas->drawImage($draw);
}

function
image_pie( &$canvas, $ox, $oy, $radius, $sd, $ed, $color = 'black' ) {

   
//  draw pie segment
    //  $ox, $oy specify the circle origin
    //  $sd, and $ed specify start and end angles in degrees
    //  degrees start from 0 = East, and go clockwise

    //  position 1 - convert degrees to radians and get first point on perimeter of circle
   
$x1     = $radius * cos($sd / 180 * 3.1416);
   
$y1     = $radius * sin($sd / 180 * 3.1416);

   
//  position 2 - convert degrees to radians and get second point on perimeter of circle
   
$x2     = $radius * cos($ed / 180 * 3.1416);
   
$y2     = $radius * sin($ed / 180 * 3.1416);

   
//  draw segment triangle - specify the 3 points and draw a polygon
   
$points = array(array('x' => $ox, 'y' => $oy), array('x' => $ox + $x1, 'y' => $oy + $y1), array('x' => $ox + $x2, 'y' => $oy + $y2));

   
image_polygon($canvas, $points, $color);

   
//  draw corrsesponding arc to complete the "pie" segment
   
image_arc($canvas, $ox - $radius, $oy - $radius, $ox + $radius, $oy + $radius, $sd, $ed, $color);
}

function
image_polygon( &$canvas, $points, $color = 'black' ) {

   
//  draw a polygon on canvas

   
$draw = new ImagickDraw();
   
$draw->setFillColor($color);
   
$draw->setStrokeColor($color);
   
$draw->setStrokeWidth(1);
   
$draw->polygon($points);
   
$canvas->drawImage($draw);
}

?>

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788