web/lib/Zend/Barcode/Renderer/Image.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Barcode
    16  * @package    Zend_Barcode
    17  * @subpackage Renderer
    17  * @subpackage Renderer
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Image.php 24593 2012-01-05 20:35:02Z matthew $
    20  * @version    $Id$
    21  */
    21  */
    22 
    22 
    23 /** @see Zend_Barcode_Renderer_RendererAbstract*/
    23 /** @see Zend_Barcode_Renderer_RendererAbstract*/
    24 require_once 'Zend/Barcode/Renderer/RendererAbstract.php';
    24 require_once 'Zend/Barcode/Renderer/RendererAbstract.php';
    25 
    25 
    26 /**
    26 /**
    27  * Class for rendering the barcode as image
    27  * Class for rendering the barcode as image
    28  *
    28  *
    29  * @category   Zend
    29  * @category   Zend
    30  * @package    Zend_Barcode
    30  * @package    Zend_Barcode
    31  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    31  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    33  */
    33  */
    34 class Zend_Barcode_Renderer_Image extends Zend_Barcode_Renderer_RendererAbstract
    34 class Zend_Barcode_Renderer_Image extends Zend_Barcode_Renderer_RendererAbstract
    35 {
    35 {
    36     /**
    36     /**
    89         parent::__construct($options);
    89         parent::__construct($options);
    90     }
    90     }
    91 
    91 
    92     /**
    92     /**
    93      * Set height of the result image
    93      * Set height of the result image
       
    94      *
    94      * @param null|integer $value
    95      * @param null|integer $value
    95      * @return Zend_Image_Barcode_Abstract
    96      * @return Zend_Image_Barcode_Abstract
    96      * @throw Zend_Image_Barcode_Exception
    97      * @throws Zend_Barcode_Renderer_Exception
    97      */
    98      */
    98     public function setHeight($value)
    99     public function setHeight($value)
    99     {
   100     {
   100         if (!is_numeric($value) || intval($value) < 0) {
   101         if (!is_numeric($value) || intval($value) < 0) {
   101             require_once 'Zend/Barcode/Renderer/Exception.php';
   102             require_once 'Zend/Barcode/Renderer/Exception.php';
   119 
   120 
   120     /**
   121     /**
   121      * Set barcode width
   122      * Set barcode width
   122      *
   123      *
   123      * @param mixed $value
   124      * @param mixed $value
   124      * @return void
   125      * @return self
       
   126      * @throws Zend_Barcode_Renderer_Exception
   125      */
   127      */
   126     public function setWidth($value)
   128     public function setWidth($value)
   127     {
   129     {
   128         if (!is_numeric($value) || intval($value) < 0) {
   130         if (!is_numeric($value) || intval($value) < 0) {
   129             require_once 'Zend/Barcode/Renderer/Exception.php';
   131             require_once 'Zend/Barcode/Renderer/Exception.php';
   146     }
   148     }
   147 
   149 
   148     /**
   150     /**
   149      * Set an image resource to draw the barcode inside
   151      * Set an image resource to draw the barcode inside
   150      *
   152      *
   151      * @param resource $value
   153      * @param $image
   152      * @return Zend_Barcode_Renderer
   154      * @return Zend_Barcode_Renderer
   153      * @throw Zend_Barcode_Renderer_Exception
   155      * @throws Zend_Barcode_Renderer_Exception
   154      */
   156      */
   155     public function setResource($image)
   157     public function setResource($image)
   156     {
   158     {
   157         if (gettype($image) != 'resource' || get_resource_type($image) != 'gd') {
   159         if (gettype($image) != 'resource' || get_resource_type($image) != 'gd') {
   158             require_once 'Zend/Barcode/Renderer/Exception.php';
   160             require_once 'Zend/Barcode/Renderer/Exception.php';
   167     /**
   169     /**
   168      * Set the image type to produce (png, jpeg, gif)
   170      * Set the image type to produce (png, jpeg, gif)
   169      *
   171      *
   170      * @param string $value
   172      * @param string $value
   171      * @return Zend_Barcode_RendererAbstract
   173      * @return Zend_Barcode_RendererAbstract
   172      * @throw Zend_Barcode_Renderer_Exception
   174      * @throws Zend_Barcode_Renderer_Exception
   173      */
   175      */
   174     public function setImageType($value)
   176     public function setImageType($value)
   175     {
   177     {
   176         if ($value == 'jpg') {
   178         if ($value == 'jpg') {
   177             $value = 'jpeg';
   179             $value = 'jpeg';
   201 
   203 
   202     /**
   204     /**
   203      * Initialize the image resource
   205      * Initialize the image resource
   204      *
   206      *
   205      * @return void
   207      * @return void
       
   208      * @throws Zend_Barcode_Exception
   206      */
   209      */
   207     protected function _initRenderer()
   210     protected function _initRenderer()
   208     {
   211     {
   209         if (!extension_loaded('gd')) {
   212         if (!extension_loaded('gd')) {
   210             require_once 'Zend/Barcode/Exception.php';
   213             require_once 'Zend/Barcode/Exception.php';
   285 
   288 
   286     /**
   289     /**
   287      * Check barcode dimensions
   290      * Check barcode dimensions
   288      *
   291      *
   289      * @return void
   292      * @return void
       
   293      * @throws Zend_Barcode_Renderer_Exception
   290      */
   294      */
   291     protected function _checkDimensions()
   295     protected function _checkDimensions()
   292     {
   296     {
   293         if ($this->_resource !== null) {
   297         if ($this->_resource !== null) {
   294             if (imagesy($this->_resource) < $this->_barcode->getHeight(true)) {
   298             if (imagesy($this->_resource) < $this->_barcode->getHeight(true)) {
   381     }
   385     }
   382 
   386 
   383     /**
   387     /**
   384      * Draw a polygon in the image resource
   388      * Draw a polygon in the image resource
   385      *
   389      *
   386      * @param string $text
   390      * @param string    $text
   387      * @param float $size
   391      * @param float     $size
   388      * @param array $position
   392      * @param array     $position
   389      * @param string $font
   393      * @param string    $font
   390      * @param integer $color
   394      * @param integer   $color
   391      * @param string $alignment
   395      * @param string    $alignment
   392      * @param float $orientation
   396      * @param float|int $orientation
       
   397      * @throws Zend_Barcode_Renderer_Exception
   393      */
   398      */
   394     protected function _drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
   399     protected function _drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
   395     {
   400     {
   396         $allocatedColor = imagecolorallocate(
   401         $allocatedColor = imagecolorallocate(
   397             $this->_resource,
   402             $this->_resource,