public function executeGetLabel() { $student = StudentPeer::retrieveByPK($this->getRequestParameter('id')); $this->forward404Unless($student); $this->student = $student; define('IMG_FORMAT_PNG', 1); define('IMG_FORMAT_JPEG', 2); define('IMG_FORMAT_WBMP', 4); define('IMG_FORMAT_GIF', 8); require 'FColor.php'; require 'BarCode.php'; require 'FDrawing.php'; include 'code128.barcode.php'; $color_black = new FColor(0, 0, 0); $color_white = new FColor(255, 255, 255); $code_generated = new code128(32, $color_black, $color_white, 1, $student->getCode(), 3); $drawing = new FDrawing(1024, 1024, '', $color_white); $drawing->init(); $drawing->add_barcode($code_generated); $drawing->draw_all(); $im = $drawing->get_im(); #$im2 = imagecreate($code_generated->lastX,$code_generated->lastY); $im2 = imagecreate(300, 100); imagecopyresized($im2, $im, 0, 0, 0, 0, 300, 100, 300, 100); ##imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY); $drawing->set_im($im2); $drawing->finish(IMG_FORMAT_PNG); }
public function getBarcodeFilePath() { $stu = $this; $filename = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('sf_app') . '/images/tmp/stu_' . $stu->getCode() . '.png'; $url_filename = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . '/images/tmp/'; define('IMG_FORMAT_PNG', 1); define('IMG_FORMAT_JPEG', 2); define('IMG_FORMAT_WBMP', 4); define('IMG_FORMAT_GIF', 8); require_once 'FColor.php'; require_once 'BarCode.php'; require_once 'FDrawing.php'; include_once 'code128.barcode.php'; $color_black = new FColor(0, 0, 0); $color_white = new FColor(255, 255, 255); /* Here is the list of the arguments: 1 - Thickness 2 - Color of bars 3 - Color of spaces 4 - Resolution 5 - Text 6 - Text Font (or 0) */ $code_generated = new code128(40, $color_black, $color_white, 2, $stu->getCode(), 0); $drawing = new FDrawing(1024, 1024, $filename, $color_white); $drawing->init(); $drawing->add_barcode($code_generated); $drawing->draw_all(); $im = $drawing->get_im(); $im2 = imagecreate($code_generated->lastX, $code_generated->lastY); imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY); $drawing->set_im($im2); $drawing->finish(1); return $url_filename . 'stu_' . $this->getCode() . '.png'; }
function cw_barcode_get($barcode, $type, $width, $height, $image_type = 8) { global $app_main_dir; $file = $app_main_dir . '/include/lib/barcode/' . $type . '.BarCode.php'; if (!is_file($file)) { return; } if (!$width || $width > 5) { $width = 2; } if (!$height) { $height = 40; } include_once $app_main_dir . '/include/lib/barcode/BarCode.php'; include_once $app_main_dir . '/include/lib/barcode/FColor.php'; include_once $app_main_dir . '/include/lib/barcode/FDrawing.php'; include_once $file; if ($image_type == IMG_FORMAT_GIF) { header("Content-Type: image/gif"); } $code = new $type($barcode, $height, $width); $drawing = new FDrawing(); $drawing->init(); $drawing->add_barcode($code); $drawing->draw_all(); $im = $drawing->get_im(); $im2 = imagecreate($code->lastX, $code->lastY); imagecopyresized($im2, $im, 0, 0, 0, 0, $code->lastX, $code->lastY, $code->lastX, $code->lastY); $drawing->set_im($im2); $drawing->finish($image_type); }
$color_black = new FColor(0, 0, 0); $color_white = new FColor(255, 255, 255); /* Here is the list of the arguments: 1 - Thickness 2 - Color of bars 3 - Color of spaces 4 - Resolution 5 - Text 6 - Text Font (0-5) */ $code_generated = new code128(25, $color_black, $color_white, 2, $psContenu, 0, "B"); /* Here is the list of the arguments 1 - Width 2 - Height 3 - Filename (empty : display on screen) 4 - Background color */ $drawing = new FDrawing(4096, 4096, "{$path}/" . $psFileName . ".png", $color_white); $drawing->init(); // You must call this method to initialize the image $drawing->add_barcode($code_generated); $drawing->draw_all(); $im = $drawing->get_im(); // Next line create the little picture, the barcode is being copied inside $im2 = imagecreate($code_generated->lastX, $code_generated->lastY); imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY); $drawing->set_im($im2); // Header that says it is an image (remove it if you save the barcode to a file) #header('Content-Type: image/png'); // Draw (or save) the image into PNG format. $drawing->finish(IMG_FORMAT_PNG); } }
public function createOrderBarcode($order_id) { $dir = Mage::getBaseDir("media") . DS . "barcode" . DS . "order" . DS; if (!is_dir_writeable($dir)) { $file = new Varien_Io_File(); $file->checkAndCreateFolder($dir); } // Creating some Color (arguments are R, G, B) $color_black = new FColor(0, 0, 0); $color_white = new FColor(255, 255, 255); $number_of_char = strlen($order_id); // to process with editted order, with order_id like 100000005-1 if ($number_of_char > 9) { $order_id = str_replace("-", "", $order_id); } $field = str_pad($order_id, 12, "0", STR_PAD_LEFT); $width = 172; $height = 62; switch (intval(Mage::getStoreConfig("barcode/general/symbology"))) { case 1: $code_generated = new code128(30, $color_black, $color_white, 1, $field, 3, "A"); break; case 2: $code_generated = new code128(30, $color_black, $color_white, 1, $field, 3, "B"); break; case 3: $code_generated = new code128(30, $color_black, $color_white, 1, $field, 3, "C"); break; case 4: $code_generated = new code39(30, $color_black, $color_white, 1, $field, 3); break; case 5: $code_generated = new i25(30, $color_black, $color_white, 1, $field, 3); break; default: $code_generated = new ean13(30, $color_black, $color_white, 1, $field, 3); $width = 110; break; } /* Here is the list of the arguments 1 - Width 2 - Height 3 - Filename (empty : display on screen) 4 - Background color */ $path = $dir . $order_id . ".png"; $imageUrl = Mage::getBaseUrl("media") . DS . "barcode" . DS . "order" . DS . $order_id . ".png"; $drawing = new FDrawing($width, $height, $path, $color_white); $drawing->init(); // You must call this method to initialize the image $drawing->add_barcode($code_generated); $drawing->draw_all(); $im = $drawing->get_im(); // Next line create the little picture, the barcode is being copied inside // $im2 = imagecreate(330,120); // // imagecopyresized($im2, $im, 189, 10, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY); // Draw (or save) the image into PNG format. $drawing->finish(IMG_FORMAT_PNG); return $path; }