ImagickDraw::arc

(PECL imagick 2, PECL imagick 3)

ImagickDraw::arc β€” РисуСт Π΄ΡƒΠ³Ρƒ

ОписаниС

public function ImagickDraw::arc(
Β Β Β Β float $start_x,
Β Β Β Β float $start_y,
Β Β Β Β float $end_x,
Β Β Β Β float $end_y,
Β Β Β Β float $start_angle,
Β Β Β Β float $end_angle
): bool
Π’Π½ΠΈΠΌΠ°Π½ΠΈΠ΅

Π€ΡƒΠ½ΠΊΡ†ΠΈΡŽ ΠΏΠΎΠΊΠ° Π½Π΅ Π·Π°Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π»ΠΈ; для знакомства доступСн Ρ‚ΠΎΠ»ΡŒΠΊΠΎ список Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ΠΎΠ².

РисуСт Π΄ΡƒΠ³Ρƒ, ΠΏΠΎΠΏΠ°Π΄Π°ΡŽΡ‰ΡƒΡŽ Π² ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΠ²Π°ΡŽΡ‰ΠΈΠΉ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΈ.

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

start_x

ΠΠ°Ρ‡Π°Π»ΡŒΠ½Π°Ρ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° X ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΠ²Π°ΡŽΡ‰Π΅Π³ΠΎ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ°

start_y

ΠΠ°Ρ‡Π°Π»ΡŒΠ½Π°Ρ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° Y ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΠ²Π°ΡŽΡ‰Π΅Π³ΠΎ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ°

end_x

ΠšΠΎΠ½Π΅Ρ‡Π½Π°Ρ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° X ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΠ²Π°ΡŽΡ‰Π΅Π³ΠΎ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ°

end_y

ΠšΠΎΠ½Π΅Ρ‡Π½Π°Ρ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° Y ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡ΠΈΠ²Π°ΡŽΡ‰Π΅Π³ΠΎ ΠΏΡ€ΡΠΌΠΎΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ°

start_angle

ΠΠ°Ρ‡Π°Π»ΡŒΠ½Ρ‹ΠΉ градус вращСния

end_angle

ΠšΠΎΠ½Π΅Ρ‡Π½Ρ‹ΠΉ градус вращСния

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π½Π΅ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ значСния послС выполнСния.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ #1 ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования ImagickDraw::arc()

<?php
function arc($strokeColor, $fillColor, $backgroundColor, $startX, $startY, $endX, $endY, $startAngle, $endAngle) {

//Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° ImagickDraw для рисования.
$draw = new \ImagickDraw();
$draw->setStrokeWidth(1);
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(2);

$draw->arc($startX, $startY, $endX, $endY, $startAngle, $endAngle);

//Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° изобраТСния, Π² ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ рисования.
$image = new \Imagick();
$image->newImage(IMAGE_WIDTH, IMAGE_HEIGHT, $backgroundColor);
$image->setImageFormat("png");

//ΠŸΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄ рисования Π² ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π΅ ImagickDraw
//Π² ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅.
$image->drawImage($draw);

//ΠžΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ изобраТСния Π² Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅
header("Content-Type: image/png");
echo
$image->getImageBlob();
}

?>
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 1 note

up
1
skmanji at manji dot org ΒΆ
14 years ago
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);
}

?>