Circles and ellipses

Add-On Circles and ellipses

Informations

Author:Olivier
License: FPDF

Description

This script allows to draw circles and ellipses.

Circle(float x, float y, float r [, string style])

x: abscissa of center.
y: ordinate of center.
r: radius.
style: style of rendering, like for Rect (D, F or FD). Default value: D.

Ellipse(float x, float y, float rx, float ry [, string style])

x: abscissa of center.
y: ordinate of center.
rx: horizontal radius.
ry: vertical radius.
style: style of rendering, like for Rect (D, F or FD). Default value: D.

Source

<?php
require('fpdf.php');

class PDF_Ellipse extends FPDF
{
function Circle($x, $y, $r, $style='D')
{
    $this->Ellipse($x, $y, $r, $r, $style);
}

function Ellipse($x, $y, $rx, $ry, $style='D')
{
    if($style=='F')
        $op='f';
    elseif($style=='FD' || $style=='DF')
        $op='B';
    else
        $op='S';
    $lx=4/3*(M_SQRT2-1)*$rx;
    $ly=4/3*(M_SQRT2-1)*$ry;
    $k=$this->k;
    $h=$this->h;
    $this->_out(sprintf('%.2F %.2F m %.2F %.2F %.2F %.2F %.2F %.2F c', 
        ($x+$rx)*$k, ($h-$y)*$k, 
        ($x+$rx)*$k, ($h-($y-$ly))*$k, 
        ($x+$lx)*$k, ($h-($y-$ry))*$k, 
        $x*$k, ($h-($y-$ry))*$k));
    $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', 
        ($x-$lx)*$k, ($h-($y-$ry))*$k, 
        ($x-$rx)*$k, ($h-($y-$ly))*$k, 
        ($x-$rx)*$k, ($h-$y)*$k));
    $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', 
        ($x-$rx)*$k, ($h-($y+$ly))*$k, 
        ($x-$lx)*$k, ($h-($y+$ry))*$k, 
        $x*$k, ($h-($y+$ry))*$k));
    $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c %s', 
        ($x+$lx)*$k, ($h-($y+$ry))*$k, 
        ($x+$rx)*$k, ($h-($y+$ly))*$k, 
        ($x+$rx)*$k, ($h-$y)*$k, 
        $op));
}
}
?>

Example

This example prints a yellow disc inside an ellipse:
<?php
require('ellipse.php');

$pdf=new PDF_Ellipse();
$pdf->AddPage();
$pdf->Ellipse(100, 50, 30, 20);
$pdf->SetFillColor(255, 255, 0);
$pdf->Circle(110, 47, 7, 'F');
$pdf->Output();
?>
View the result here.

Download

ZIP | TGZ
An Error Occurred:Internal Server Error

Oops! An Error Occurred

The server returned a "500Internal Server Error".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.