fpdf
PHP powered
home was ist fpdf? downloads & add-ons dokumentation faq forum impressum links kontakt
 

Downloads > Add-On

 
         
 

Circles and ellipses

Informations

Author: Olivier
License: Freeware

Description

This script allows to draw circles and ellipses. It requires FPDF 1.51.

function 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.

function 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.

The example prints a yellow disc inside an ellipse.

Note: ellipse support will be added in version 1.6.

Source

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

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

function Ellipse($x, $y, $rx, $ry, $style='D')
{
    if($style=='F')
        $op='f';
    elseif($style=='FD' or $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));
}
}

$pdf=new PDF();
$pdf->Open();
$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
 






 
         
         
 
 
fpdf.de © Copyright 2004-2006 carrib internet solutions - Beachten Sie bitte die Nutzungsbedingungen
Eine Verwendung der auf fpdf.de befindlichen Inhalte (Texte, Grafiken) ist nur mit Zustimmung des Betreibers zulässig.