Your IP : 216.73.216.48


Current Path : /hdd/hdd11/www/vlevski/enter/_old_files/
Upload File :
Current File : /hdd/hdd11/www/vlevski/enter/_old_files/BarcodeBase.php

<?php
namespace vlevski\Barcode;
abstract class BarcodeBase
{
	protected $img = null;
	protected $x = 0;
	protected $y = 0;
	protected $humanText = true;
	protected $jpgQuality = 100;
	abstract public function setData($data);
	abstract public function draw();
	public function setDimensions($x, $y)
	{
		$this->x = (int) $x;
		$this->y = (int) $y;

		return $this;
	}
	public function setQuality($q)
	{
		$this->jpgQuality = (int) $q;
		return $this;
	}
	public function enableHumanText($enable = true)
	{
		$this->humanText = (boolean) $enable;
		return $this;
	}
	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;
		}
	}
	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;
		}
	}
	public function base64()
	{
		ob_start();
		$this->output();
		return base64_encode(ob_get_clean());
	}
}