[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/driver/ -> gd.php (summary)

File containing the ezcGraphGdDriver class

Copyright: Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
License: http://ez.no/licenses/new_bsd New BSD License
Version: 1.5
File Size: 1236 lines (43 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ezcGraphGdDriver:: (21 methods):
  __construct()
  getImage()
  allocate()
  imageCreateFrom()
  supersample()
  drawPolygon()
  drawLine()
  getTextBoundings()
  renderText()
  drawTextBox()
  drawAllTexts()
  drawCircleSector()
  drawCircularArcStep()
  drawCircularArc()
  drawCircle()
  drawImage()
  addImages()
  getMimeType()
  renderToOutput()
  render()
  getResource()


Class: ezcGraphGdDriver  - X-Ref

Driver using PHPs ext/gd to draw images. The GD extension is available on
nearly all PHP installations, but slow and produces slightly incorrect
results.

The driver can make use of the different font extensions available with
ext/gd. It is possible to use Free Type 2, native TTF and PostScript Type 1
fonts.

The options of this driver are configured in {@link ezcGraphGdDriverOptions}
extending the basic driver options class {@link ezcGraphDriverOptions}.

<code>
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzGreen();
$graph->title = 'Access statistics';
$graph->legend = false;

$graph->driver = new ezcGraphGdDriver();
$graph->options->font = 'tutorial_font.ttf';

// Generate a Jpeg with lower quality. The default settings result in a image
// with better quality.
//
// The reduction of the supersampling to 1 will result in no anti aliasing of
// the image. JPEG is not the optimal format for grapics, PNG is far better for
// this kind of images.
$graph->driver->options->supersampling = 1;
$graph->driver->options->jpegQuality = 100;
$graph->driver->options->imageFormat = IMG_JPEG;

$graph->data['Access statistics'] = new ezcGraphArrayDataSet( array(
'Mozilla' => 19113,
'Explorer' => 10917,
'Opera' => 1464,
'Safari' => 652,
'Konqueror' => 474,
) );

$graph->render( 400, 200, 'tutorial_dirver_gd.jpg' );
</code>

__construct( array $options = array()   X-Ref
Constructor

param: array $options Default option array
return: void

getImage()   X-Ref
Returns the image resource to draw on.

If no resource exists the image will be created. The size of the
returned image depends on the supersampling factor and the size of the
chart.

return: resource

allocate( ezcGraphColor $color )   X-Ref
Allocates a color

This function tries to allocate the requested color. If the color
already exists in the imaga it will be reused.

param: ezcGraphColor $color
return: int Color index

imageCreateFrom( $file )   X-Ref
Creates an image resource from an image file

param: string $file Filename
return: resource Image

supersample( $value )   X-Ref
Supersamples a single coordinate value.

Applies supersampling to a single coordinate value.

param: float $value Coordinate value
return: float Supersampled coordinate value

drawPolygon( array $points, ezcGraphColor $color, $filled = true, $thickness = 1. )   X-Ref
Draws a single polygon.

param: array $points Point array
param: ezcGraphColor $color Polygon color
param: mixed $filled Filled
param: float $thickness Line thickness
return: void

drawLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color, $thickness = 1. )   X-Ref
Draws a line

param: ezcGraphCoordinate $start Start point
param: ezcGraphCoordinate $end End point
param: ezcGraphColor $color Line color
param: float $thickness Line thickness
return: void

getTextBoundings( $size, ezcGraphFontOptions $font, $text )   X-Ref
Returns boundings of text depending on the available font extension

param: float $size Textsize
param: ezcGraphFontOptions $font Font
param: string $text Text
return: ezcGraphBoundings Boundings of text

renderText( $image, $text, $type, $path, ezcGraphColor $color, ezcGraphCoordinate $position, $size, ezcGraphRotation $rotation = null )   X-Ref
Render text depending of font type and available font extensions

param: resource $image Image resource
param: string $text Text
param: int $type Font type
param: string $path Font path
param: ezcGraphColor $color Font color
param: ezcGraphCoordinate $position Position
param: float $size Textsize
param: ezcGraphRotation $rotation
return: void

drawTextBox( $string, ezcGraphCoordinate $position, $width, $height, $align, ezcGraphRotation $rotation = null )   X-Ref
Writes text in a box of desired size

param: string $string Text
param: ezcGraphCoordinate $position Top left position
param: float $width Width of text box
param: float $height Height of text box
param: int $align Alignement of text
param: ezcGraphRotation $rotation
return: void

drawAllTexts()   X-Ref
Draw all collected texts

The texts are collected and their maximum possible font size is
calculated. This function finally draws the texts on the image, this
delayed drawing has two reasons:

1) This way the text strings are always on top of the image, what
results in better readable texts
2) The maximum possible font size can be calculated for a set of texts
with the same font configuration. Strings belonging to one chart
element normally have the same font configuration, so that all texts
belonging to one element will have the same font size.

return: void

drawCircleSector( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )   X-Ref
Draws a sector of cirlce

param: ezcGraphCoordinate $center Center of circle
param: mixed $width Width
param: mixed $height Height
param: mixed $startAngle Start angle of circle sector
param: mixed $endAngle End angle of circle sector
param: ezcGraphColor $color Color
param: mixed $filled Filled
return: void

drawCircularArcStep( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color )   X-Ref
Draws a single element of a circular arc

ext/gd itself does not support something like circular arcs, so that
this functions draws rectangular polygons as a part of circular arcs
to interpolate them. This way it is possible to apply a linear gradient
to the circular arc, because we draw single steps anyway.

param: ezcGraphCoordinate $center Center of ellipse
param: integer $width Width of ellipse
param: integer $height Height of ellipse
param: integer $size Height of border
param: float $startAngle Starting angle of circle sector
param: float $endAngle Ending angle of circle sector
param: ezcGraphColor $color Color of Border
return: void

drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled = true )   X-Ref
Draws a circular arc

param: ezcGraphCoordinate $center Center of ellipse
param: integer $width Width of ellipse
param: integer $height Height of ellipse
param: integer $size Height of border
param: float $startAngle Starting angle of circle sector
param: float $endAngle Ending angle of circle sector
param: ezcGraphColor $color Color of Border
param: bool $filled
return: void

drawCircle( ezcGraphCoordinate $center, $width, $height, ezcGraphColor $color, $filled = true )   X-Ref
Draw circle

param: ezcGraphCoordinate $center Center of ellipse
param: mixed $width Width of ellipse
param: mixed $height height of ellipse
param: ezcGraphColor $color Color
param: mixed $filled Filled
return: void

drawImage( $file, ezcGraphCoordinate $position, $width, $height )   X-Ref
Draw an image

The actual drawing of the image is delayed, to not apply supersampling
to the image. The image will normally be resized using the gd function
imagecopyresampled, which provides nice antialiased scaling, so that
additional supersampling would make the image look blurred. The delayed
images will be pre-processed, so that they are draw in the back of
everything else.

param: mixed $file Image file
param: ezcGraphCoordinate $position Top left position
param: mixed $width Width of image in destination image
param: mixed $height Height of image in destination image
return: void

addImages( $image )   X-Ref
Draw all images to image resource handler

param: resource $image Image to draw on
return: resource Updated image resource

getMimeType()   X-Ref
Return mime type for current image format

return: string

renderToOutput()   X-Ref
Render image directly to output

The method renders the image directly to the standard output. You
normally do not want to use this function, because it makes it harder
to proper cache the generated graphs.

return: void

render( $file )   X-Ref
Finally save image

param: string $file Destination filename
return: void

getResource()   X-Ref
Get resource of rendered result

Return the resource of the rendered result. You should not use this
method before you called either renderToOutput() or render(), as the
image may not be completely rendered until then.

return: resource



Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7