Introduction
This class allows you to draw a barcode on a GD2 image. Of course, you can use another class to draw the barcode.
BCGDrawing's Methods
- __construct($filename, $color) — Construct the drawing
- getFilename($filename) — Gets the filename
- setFilename($filename) — Sets the filename
- get_im() — Gets the GD2 image
- set_im($im) — Sets the GD2 image
- getBarcode($barcode) — Gets the barcode associated
- setBarcode($barcode) — Sets the barcode to use
- getDPI() — Gets the DPI for supported filetype
- setDPI($dpi) — Sets the DPI for supported filetype
- getRotationAngle() — Gets the rotation angle in degree
- setRotationAngle($degree) — Sets the rotation angle in degree
- draw() — Draws the barcode on the GD2 image
- finish($image_style = IMG_FORMAT_PNG, $quality = 100) — Finishes the drawing by saving it or displaying it
- destroy() — Destroys the memory associated with the image
Code Example
// To get an example on how to use this class, check barcode classes. Methods Explanation
-
__construct($filename, $color)
— Construct the drawing DescriptionCreates the class. The first argument must be the path where you want to save the barcode. If you enter an empty string, the image will be displayed when you call the finish() method.
The second argument is the background color of the drawing. This must be a BCGColor object.
These two arguments are optional. -
getFilename($filename)
— Gets the filename DescriptionGets the filename.Returnsstring
-
setFilename($filename)
— Sets the filename DescriptionSets the filename.
-
get_im()
— Gets the GD2 image DescriptionGets the GD2 image to make other operations.Returnsresource - PHP image
-
set_im($im)
— Sets the GD2 image DescriptionSets the GD2 image into the class. This image will be used instead of creating a new one. You must have the correct size of the image depending on the size returned by the getDimension() method.
-
getBarcode($barcode)
— Gets the barcode associated DescriptionGets the barcode associated.Returns
-
setBarcode($barcode)
— Sets the barcode to use DescriptionSets the barcode. The class must be a BCGBarcode object.
-
getDPI()
— Gets the DPI for supported filetype DescriptionGets the DPI specified for the image. The value can also be NULL. This means the image will be written without any DPI attribute.Returnsint - DPI or NULL
-
setDPI($dpi)
— Sets the DPI for supported filetype DescriptionSets the DPI for the image. If you don't specify any DPI for the image, a value NULL will be used. Using a value NULL improves the performance when generating the image. The resulting image will be 72DPI if you don't specify any DPI.
Only PNG and JPG filetypes can support the DPI setting. -
getRotationAngle()
— Gets the rotation angle in degree DescriptionGets the rotation angle for the image in degrees. (clockwise)Returnsint - value between 0 and 360
-
setRotationAngle($degree)
— Sets the rotation angle in degree DescriptionSets the rotation angle for the image in degrees. (clockwise)
Note that your server may not support the imagerotate() function. -
draw()
— Draws the barcode on the GD2 image DescriptionDraws the barcode on the GD2 image. If you didn't specify any image with the set_im() method, a new image will be created.
-
finish($image_style = IMG_FORMAT_PNG, $quality = 100)
— Finishes the drawing by saving it or displaying it DescriptionWrites the image in the specified file. The file has been specified when you constructed the class, if you didn't, the image will be displayed.
The first argument $image_style can take four different values:- BCGDrawing::IMG_FORMAT_PNG : will draw in PNG format
- BCGDrawing::IMG_FORMAT_JPEG : will draw in JPG format. Use the second argument
- BCGDrawing::IMG_FORMAT_GIF : will draw in GIF format
- BCGDrawing::IMG_FORMAT_WBMP : will draw in WBMP format
The default value is 100. -
destroy()
— Destroys the memory associated with the image DescriptionThis method is automatically called with PHP5. You have to call this method with PHP4 or the image will be destroyed at the end of the script.
