You are here

function barcode_generate_image in Barcode 6.2

Same name and namespace in other branches
  1. 7.2 includes/barcode.plugins.inc \barcode_generate_image()

Creates or return the plugin filename containing the given encoding.

1 call to barcode_generate_image()
theme_barcode_image in ./barcode.module
Theme function for the barcode image.

File

includes/barcode.plugins.inc, line 68
Code to load barcode symbology plugins

Code

function barcode_generate_image($barcode) {
  $filename_noformat = file_create_path($barcode['default_path']) . '/' . $barcode['value'] . $barcode['encoding'];
  $filename = $filename_noformat . '.' . $barcode['image_format'];

  // First check if the images already exists.
  if (!file_exists($filename)) {
    $plugin = barcode_load_plugin($barcode['encoding']);
    $settings->encode = $barcode['encoding'];
    $settings->height = $barcode['height'];
    $settings->scale = $barcode['scale'];
    $settings->color = array(
      hexdec(substr($barcode['barcolor'], 1, 2)),
      hexdec(substr($barcode['barcolor'], 3, 2)),
      hexdec(substr($barcode['barcolor'], 5, 2)),
    );
    $settings->bgcolor = array(
      hexdec(substr($barcode['bgcolor'], 1, 2)),
      hexdec(substr($barcode['bgcolor'], 3, 2)),
      hexdec(substr($barcode['bgcolor'], 5, 2)),
    );
    $settings->font = $barcode['font'];
    $settings->format = $barcode['image_format'];
    $settings->filename_no_format = $filename_noformat;
    $settings->n2w = 2;
    barcode_plugin_generate_image($plugin, $barcode['value'], $settings);
    drupal_set_message(t('The %barcode barcode image has been generated using %encoding encoding.', array(
      '%barcode' => $barcode['value'],
      '%encoding' => $barcode['encoding'],
    )));
  }
  if (!file_exists($filename)) {
    return FALSE;
  }
  return $filename;
}