Created
February 22, 2013 08:01
-
-
Save thelebster/5011643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function MYMODULE_generate_barcode128($string, $rebuild = FALSE) { | |
| $filepath = 'barcodes'; | |
| $filename = "{$filepath}/" . md5($string) . ".png"; | |
| // First check if the images already exists. | |
| if (!file_exists(file_default_scheme()."://{$filename}") || $rebuild) { | |
| $zend_path = libraries_get_path('Zend'); | |
| set_include_path(get_include_path() . PATH_SEPARATOR . $zend_path); | |
| require_once 'Zend/Loader/Autoloader.php'; | |
| Zend_Loader_Autoloader::getInstance(); | |
| $barcodeOptions = array( | |
| 'text' => $string, | |
| 'barHeight' => 50, | |
| 'factor' => 2 | |
| ); | |
| // No required options | |
| $rendererOptions = array( | |
| 'imageType' => 'png' | |
| ); | |
| // Draw the barcode in a new image | |
| $img = Zend_Barcode::draw('code128', 'image', $barcodeOptions, $rendererOptions); | |
| ob_start(); | |
| @imagepng($img); | |
| $file = file_save_data(ob_get_contents(), file_default_scheme()."://{$filename}", TRUE); | |
| ob_end_clean(); | |
| @imagedestroy($img); | |
| $file_uri = $file->uri; | |
| } | |
| else { | |
| $file_uri = file_build_uri($filename); | |
| } | |
| $fileurl = file_create_url($file_uri); | |
| return $fileurl; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment