I suggest you add an API level function called makeimage, to be used independently of theming. A higher level version of barcode_generateimage

So function theme_barcode_image($barcode_value, $encoding = NULL) becomes

function theme_barcode_image($barcode_value, $encoding = NULL) {

 if (empty($barcode_value)) {
    return '';
  }

  $filename = barcode_makeimage ($barcode_value, $encoding);

  if (!$filename) {
    drupal_set_message(t('An error occured while generating the barcode.'), 'error');
    return '';
  }
  
  return theme('image', $filename, $barcode_value, $barcode_value, array('class' => 'barcode'));

}

and the function is the bulk of that function.

function barcode_makeimage ($barcode_value, $encoding = NULL) {

  $barcode = barcode_get_settings();
  $barcode['value'] = $barcode_value;

  if (isset($encoding)) {
    $barcode['encoding'] = $encoding;
  }

  module_load_include('inc', 'barcode', 'includes/barcode.plugins');
  $filename = barcode_generate_image($barcode);

  return $filename;
}

To me that's more useful than the lower-level function because it encapsulates all the variability in making an image and hides details. Not sure about the makeimage name though.

Comments

skyredwang’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.