You are here

function barcode_generate_image in Barcode 7.2

Same name and namespace in other branches
  1. 6.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 70
Code to load barcode symbology plugins

Code

function barcode_generate_image($barcode, $variables) {
  $name = md5($variables['barcode_value']);
  $filename_noformat = $barcode['default_path'] . '/' . $name . $variables['encoding'];
  $filename = $filename_noformat . '.' . $variables['image_format'];

  // First check if the images already exists.
  if (!file_exists($filename)) {
    $plugin = barcode_load_plugin($variables['encoding']);
    $settings = new stdClass();
    $settings->default_path = drupal_realpath($barcode['default_path']);
    $settings->encode = $variables['encoding'];
    $settings->height = $variables['height'];
    $settings->font = $barcode['font'];
    $settings->format = $variables['image_format'];

    // GD library fails on stream wrappers - get the realpath.
    $settings->filename_no_format = drupal_realpath($filename_noformat);
    $settings->n2w = 2;
    if ($variables['encoding'] != 'QRCODE') {
      $settings->color = array(
        hexdec(substr($variables['barcolor'], 1, 2)),
        hexdec(substr($variables['barcolor'], 3, 2)),
        hexdec(substr($variables['barcolor'], 5, 2)),
      );
      $settings->bgcolor = array(
        hexdec(substr($variables['bgcolor'], 1, 2)),
        hexdec(substr($variables['bgcolor'], 3, 2)),
        hexdec(substr($variables['bgcolor'], 5, 2)),
      );
      $settings->scale = $variables['scale'];
    }
    barcode_plugin_generate_image($plugin, $variables['barcode_value'], $settings);
  }
  if (!file_exists($filename)) {
    watchdog('barcode', 'Failed to generate image using settings @settings', array(
      '@settings' => print_r($settings, TRUE),
    ));
    return FALSE;
  }
  return $filename;
}