Source of file BarcodeBase.php
Size: 3,326 Bytes - Last Modified: 2021-12-24T06:49:56+00:00
/var/www/docs.ssmods.com/process/src/code/BarcodeBase.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 | <?php /** * * @package Barcode Creator * @copyright (c) 2011 emberlabs.org * @license http://opensource.org/licenses/mit-license.php The MIT License * @link https://github.com/samt/barcode * * Minimum Requirement: PHP 5.3.0 */ /** * emberlabs Barcode Creator - Barcode Base * Abstract Base * * * @license http://opensource.org/licenses/mit-license.php The MIT License * @link https://github.com/samt/barcode */ abstract class BarcodeBase { /* * GD Resource * @var resource */ protected $img = null; /* * @var int x (width) */ protected $x = 0; /* * @var int y (height) */ protected $y = 0; /* * Print Human Text? * @var bool */ protected $humanText = true; /* * Quality * @var int */ protected $jpgQuality = 85; /* * (Abstract) Set the data * * @param mixed data - (int or string) Data to be encoded * @return instance of \emberlabs\Barcode\BarcodeInterface * @return throws \OverflowException */ abstract public function setData($data); /* * (Abstract) Draw the image * * @return void */ abstract public function draw(); /* * Set the Dimensions * * @param int x * @param int y * @return instance of \emberlabs\Barcode\BarcodeBase */ public function setDimensions($x, $y) { $this->x = (int) $x; $this->y = (int) $y; return $this; } /* * Set Quality * @param int q - jpeg quality * @return instance of \emberlabs\Barcode\BarcodeBase */ public function setQuality($q) { $this->jpgQuality = (int) $q; return $this; } /* * Display human readable text below the code * @param boolean enable - Enable the human readable text * @return instance of \emberlabs\Barcode\BarcodeBase */ public function enableHumanText($enable = true) { $this->humanText = (boolean) $enable; return $this; } /* * Output Image to the buffer * * @return void */ public function output($type = 'png') { switch($type) { case 'jpg': case 'jpeg': imagejpeg($this->img, NULL, $this->jpgQuality); break; case 'gif': imagegif($this->img); break; case 'png': default: imagepng($this->img); break; } } /* * Save Image * * @param string filename - File to write to (needs to have .png, .gif, or * .jpg extension) * @return void * @throws \RuntimeException - If the file could not be written or some * other I/O error. */ public function save($filename) { $type = strtolower(substr(strrchr($filename, '.'), 1)); switch($type) { case 'jpg': case 'jpeg': imagejpeg($this->img, $filename, $this->jpgQuality); break; case 'gif': imagegif($this->img, $filename); break; case 'png': imagepng($this->img, $filename); break; default: throw new \RuntimeException("Could not determine file type."); break; } } /* * Base64 Encoded * For ouput in-page * @return void */ public function base64() { ob_start(); $this->output(); return base64_encode(ob_get_clean()); } /** * Rotate the drawn image * @param integer $deg Angle of rotation (counter-clockwise) * @return instance of \emberlabs\Barcode\BarcodeBase */ public function rotate($deg = 180){ if ($this->img) $this->img = imagerotate($this->img, $deg, 0); return $this; } } |