略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ImagickDraw::ellipse

2024-11-13

ImagickDraw::ellipse

(PECL imagick 2, PECL imagick 3)

ImagickDraw::ellipseDraws an ellipse on the image

说明

public ImagickDraw::ellipse(
    float $ox,
    float $oy,
    float $rx,
    float $ry,
    float $start,
    float $end
): bool
警告

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

Draws an ellipse on the image.

参数

ox

oy

rx

ry

start

end

返回值

没有返回值。

范例

示例 #1 ImagickDraw::ellipse() example

<?php
function ellipse($strokeColor$fillColor$backgroundColor) {

    
$draw = new \ImagickDraw();
    
$draw->setStrokeColor($strokeColor);
    
$draw->setFillColor($fillColor);

    
$draw->setStrokeWidth(2);
    
$draw->setFontSize(72);

    
$draw->ellipse(12570100500360);
    
$draw->ellipse(35070100500315);

    
$draw->push();
    
$draw->translate(125250);
    
$draw->rotate(30);
    
$draw->ellipse(00100500360);
    
$draw->pop();

    
$draw->push();
    
$draw->translate(350250);
    
$draw->rotate(30);
    
$draw->ellipse(00100500315);
    
$draw->pop();

    
$imagick = new \Imagick();
    
$imagick->newImage(500500$backgroundColor);
    
$imagick->setImageFormat("png");

    
$imagick->drawImage($draw);

    
header("Content-Type: image/png");
    echo 
$imagick->getImageBlob();
}

?>
add a noteadd a note

User Contributed Notes 1 note

up
-1
Axeia
13 years ago
<?php
/**
* Please note that if you use a stroke. ( Imagick::setStrokeWidth( 2 ) ) the
* stroke is drawn outside the ellipse dimensions.
*
* @param float $ox - Offset X, distance from the center of the ellipse till the left border of the image
* @param float $oy - Offset Y, distance from the center of the ellipse till the top of the image
* @param float $rx - X radius
* @param float $ry - Y radius
* @param float float $start - Starting angle in degrees.
* @param float float $end - End angle in degrees.
*
*/
ImagickDraw::ellipse( float $ox  , float $oy  , float $rx  , float $ry  , float $start  , float $end  );
?>

Example of drawing a full ellipse (from 0, 360) and outputting it as a PNG.
Do note, that this is  by default anti-aliased unlike the GD functions which only support it on lines that aren't on a transparent background.
<?php
$width
200;
$height = 100;
$border = 2;

$img = new Imagick();
$img->newImage( $width, $height, new ImagickPixel( 'transparent' ) );

$draw = new ImagickDraw();
$draw->setStrokeColor( new ImagickPixel( 'black' ) );
$draw->setStrokeWidth( 2 );
$draw->setFillColor( new ImagickPixel( 'transparent' ) );
//Substract the border from the radius so it doesn't fall outside the screen.
$draw->ellipse( $width/2, $height/2, ($width/2)-$border, ($height/2)-$border, 0, 360 );
$img->drawImage( $draw );
$img->setImageFormat( "png" );

header( "Content-Type: image/png" );
echo
$img;
?>

官方地址:https://www.php.net/manual/en/imagickdraw.ellipse.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3