Manual - Drawing


This class allows you to draw a barcode on an image resource. Of course, you can use another class to draw the barcode.


BCGDrawing's Methods

Code Example

// To get an example on how to use this class, check barcode classes.

Method explanations

  • __construct($filename, $color) — Construct the drawing
    Creates 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() — Gets the filename
    Gets the filename.
  • setFilename($filename) — Sets the filename
    Sets the filename.
  • getImage() — Gets the image resource
    Gets the image resource to make other operations.
    resource - PHP image
  • setImage($im) — Sets the image resource
    Sets the image resource 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() — Gets the barcode associated
    Gets the barcode associated.
  • setBarcode($barcode) — Sets the barcode to use
    Sets the barcode. The class must be a %class.barcode% object.
  • getDpi() — Gets the DPI for supported filetype
    Gets the DPI specified for the image. The value can also be null. This means the image will be written without any DPI attribute.
    int - DPI or null
  • setDpi($dpi) — Sets the DPI for supported filetype
    Sets 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
    Gets the rotation angle for the image in degrees. (clockwise)
    int - value between 0 and 360
  • setRotationAngle($degree) — Sets the rotation angle in degree
    Sets 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 image resource
    Draws the barcode on the image resource. If you didn't specify any image with the setImage() method, a new image will be created.
  • finish($image_style) — Finishes the drawing by saving it or displaying it
    Writes 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 second argument $quality is used only if you use the JPG format. It allows you to specify the quality percentage of the image.
    The default value is 100.
  • destroy() — Destroys the memory associated with the image
    This 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.