Graph: ezcGraphGdDriver
[ ]
[ Gallery ]
[ ]
[ ]
[ ]
[ ]
Class: ezcGraphGdDriver
|
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. [
source]
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.
1. $graph = new ezcGraphPieChart();
2. $graph->palette = new ezcGraphPaletteEzGreen();
3. $graph->title = 'Access statistics';
4. $graph->legend = false;
5.
6. $graph->driver = new ezcGraphGdDriver();
7. $graph->options->font = 'tutorial_font.ttf';
8.
9. // Generate a Jpeg with lower quality. The default settings result in a image
10. // with better quality.
11. //
12. // The reduction of the supersampling to 1 will result in no anti aliasing of
13. // the image. JPEG is not the optimal format for grapics, PNG is far better for
14. // this kind of images.
15. $graph->driver->options->supersampling = 1;
16. $graph->driver->options->jpegQuality = 100;
17. $graph->driver->options->imageFormat = IMG_JPEG;
18.
19. $graph->data['Access statistics'] = new ezcGraphArrayDataSet( array(
20. 'Mozilla' => 19113,
21. 'Explorer' => 10917,
22. 'Opera' => 1464,
23. 'Safari' => 652,
24. 'Konqueror' => 474,
25. ) );
26.
27. $graph->render( 400, 200, 'tutorial_dirver_gd.jpg' );
Parents
ezcGraphDriver
|
--ezcGraphGdDriver
Member Variables
|
protected resource |
$image
Image resource |
|
protected array |
$preProcessImages
= array()
Array with image files to draw |
|
protected array |
$psFontResources
= array()
Contains resources for already loaded ps fonts.
array( path => resource ) |
|
protected array |
$strings
= array()
List of strings to draw
array ( array( 'text' => array( 'strings' ), 'options' => ezcGraphFontOptions, ) |
Inherited Member Variables
From
ezcGraphDriver:
Method Summary
|
protected resource |
addImages(
$image )
Draw all images to image resource handler |
|
protected int |
allocate(
$color )
Allocates a color |
|
protected void |
drawAllTexts(
)
Draw all collected texts |
|
public void |
drawCircle(
$center, $width, $height, $color, [$filled = true] )
Draw circle |
|
public void |
drawCircleSector(
$center, $width, $height, $startAngle, $endAngle, $color, [$filled = true] )
Draws a sector of cirlce |
|
public void |
drawCircularArc(
$center, $width, $height, $size, $startAngle, $endAngle, $color, [$filled = true] )
Draws a circular arc |
|
protected void |
drawCircularArcStep(
$center, $width, $height, $size, $startAngle, $endAngle, $color )
Draws a single element of a circular arc |
|
public void |
drawImage(
$file, $position, $width, $height )
Draw an image |
|
public void |
drawLine(
$start, $end, $color, [$thickness = 1.] )
Draws a line |
|
public void |
drawPolygon(
$points, $color, [$filled = true], [$thickness = 1.] )
Draws a single polygon. |
|
public void |
drawTextBox(
$string, $position, $width, $height, $align, [$rotation = null] )
Writes text in a box of desired size |
|
protected resource |
getImage(
)
Returns the image resource to draw on. |
|
public string |
getMimeType(
)
Return mime type for current image format |
|
public resource |
getResource(
)
Get resource of rendered result |
|
protected ezcGraphBoundings |
getTextBoundings(
$size, $font, $text )
Returns boundings of text depending on the available font extension |
|
protected resource |
imageCreateFrom(
$file )
Creates an image resource from an image file |
|
public void |
render(
$file )
Finally save image |
|
protected void |
renderText(
$image, $text, $type, $path, $color, $position, $size, [$rotation = null], $rotation
)
Render text depending of font type and available font extensions |
|
public void |
renderToOutput(
)
Render image directly to output |
|
protected float |
supersample(
$value )
Supersamples a single coordinate value. |
Inherited Methods
From
ezcGraphDriver :
Methods
addImages
resource addImages(
resource
$image )
Draw all images to image resource handler
Parameters
| Name |
Type |
Description |
$image |
resource |
Image to draw on |
allocate
Allocates a color
This function tries to allocate the requested color. If the color already exists in the imaga it will be reused.
Parameters
drawAllTexts
void drawAllTexts(
)
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.
drawCircle
Draw circle
Parameters
| Name |
Type |
Description |
$center |
ezcGraphCoordinate |
Center of ellipse |
$width |
mixed |
Width of ellipse |
$height |
mixed |
height of ellipse |
$color |
ezcGraphColor |
Color |
$filled |
mixed |
Filled |
Redefinition of
drawCircleSector
void drawCircleSector(
ezcGraphCoordinate
$center, mixed
$width, mixed
$height, mixed
$startAngle, mixed
$endAngle,
ezcGraphColor
$color, [mixed
$filled = true] )
Draws a sector of cirlce
Parameters
| Name |
Type |
Description |
$center |
ezcGraphCoordinate |
Center of circle |
$width |
mixed |
Width |
$height |
mixed |
Height |
$startAngle |
mixed |
Start angle of circle sector |
$endAngle |
mixed |
End angle of circle sector |
$color |
ezcGraphColor |
Color |
$filled |
mixed |
Filled |
Redefinition of
drawCircularArc
void drawCircularArc(
ezcGraphCoordinate
$center, integer
$width, integer
$height, integer
$size, float
$startAngle, float
$endAngle,
ezcGraphColor
$color, [bool
$filled = true] )
Draws a circular arc
Parameters
| Name |
Type |
Description |
$center |
ezcGraphCoordinate |
Center of ellipse |
$width |
integer |
Width of ellipse |
$height |
integer |
Height of ellipse |
$size |
integer |
Height of border |
$startAngle |
float |
Starting angle of circle sector |
$endAngle |
float |
Ending angle of circle sector |
$color |
ezcGraphColor |
Color of Border |
$filled |
bool |
|
Redefinition of
drawCircularArcStep
void drawCircularArcStep(
ezcGraphCoordinate
$center, integer
$width, integer
$height, integer
$size, float
$startAngle, float
$endAngle,
ezcGraphColor
$color )
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.
Parameters
| Name |
Type |
Description |
$center |
ezcGraphCoordinate |
Center of ellipse |
$width |
integer |
Width of ellipse |
$height |
integer |
Height of ellipse |
$size |
integer |
Height of border |
$startAngle |
float |
Starting angle of circle sector |
$endAngle |
float |
Ending angle of circle sector |
$color |
ezcGraphColor |
Color of Border |
drawImage
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.
Parameters
| Name |
Type |
Description |
$file |
mixed |
Image file |
$position |
ezcGraphCoordinate |
Top left position |
$width |
mixed |
Width of image in destination image |
$height |
mixed |
Height of image in destination image |
Redefinition of
drawLine
Draws a line
Parameters
Redefinition of
drawPolygon
void drawPolygon(
$points,
ezcGraphColor
$color, [mixed
$filled = true], [float
$thickness = 1.] )
Draws a single polygon.
Parameters
| Name |
Type |
Description |
$points |
array |
Point array |
$color |
ezcGraphColor |
Polygon color |
$filled |
mixed |
Filled |
$thickness |
float |
Line thickness |
Redefinition of
drawTextBox
void drawTextBox(
string
$string,
ezcGraphCoordinate
$position, float
$width, float
$height, int
$align, [
$rotation = null] )
Writes text in a box of desired size
Parameters
| Name |
Type |
Description |
$string |
string |
Text |
$position |
ezcGraphCoordinate |
Top left position |
$width |
float |
Width of text box |
$height |
float |
Height of text box |
$align |
int |
Alignement of text |
$rotation |
ezcGraphRotation |
|
Redefinition of
getImage
resource getImage(
)
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.
getMimeType
string getMimeType(
)
Return mime type for current image format
Redefinition of
getResource
resource getResource(
)
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.
getTextBoundings
Returns boundings of text depending on the available font extension
Parameters
Redefinition of
imageCreateFrom
resource imageCreateFrom(
string
$file )
Creates an image resource from an image file
Parameters
| Name |
Type |
Description |
$file |
string |
Filename |
render
void render(
string
$file )
Finally save image
Parameters
| Name |
Type |
Description |
$file |
string |
Destination filename |
Redefinition of
renderText
void renderText(
resource
$image, string
$text, int
$type, string
$path,
ezcGraphColor
$color,
ezcGraphCoordinate
$position, float
$size, [
$rotation = null], ezcGraphRotation
$rotation
)
Render text depending of font type and available font extensions
Parameters
| Name |
Type |
Description |
$image |
resource |
Image resource |
$text |
string |
Text |
$type |
int |
Font type |
$path |
string |
Font path |
$color |
ezcGraphColor |
Font color |
$position |
ezcGraphCoordinate |
Position |
$size |
float |
Textsize |
$rotation
|
ezcGraphRotation |
|
$rotation |
ezcGraphRotation |
|
renderToOutput
void renderToOutput(
)
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.
Redefinition of
supersample
float supersample(
float
$value )
Supersamples a single coordinate value.
Applies supersampling to a single coordinate value.
Parameters
| Name |
Type |
Description |
$value |
float |
Coordinate value |
Last updated: Mon, 09 Feb 2009