PHPExcel_Worksheet
[ class tree: PHPExcel_Worksheet ] [ index: PHPExcel_Worksheet ] [ all elements ]

Source for file MemoryDrawing.php

Documentation is available at MemoryDrawing.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2011 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Worksheet
  23.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Worksheet_MemoryDrawing
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Worksheet
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. {
  37.     /* Rendering functions */
  38.     const RENDERING_DEFAULT                    = 'imagepng';
  39.     const RENDERING_PNG                        = 'imagepng';
  40.     const RENDERING_GIF                        = 'imagegif';
  41.     const RENDERING_JPEG                    = 'imagejpeg';
  42.  
  43.     /* MIME types */
  44.     const MIMETYPE_DEFAULT                    = 'image/png';
  45.     const MIMETYPE_PNG                        = 'image/png';
  46.     const MIMETYPE_GIF                        = 'image/gif';
  47.     const MIMETYPE_JPEG                        = 'image/jpeg';
  48.  
  49.     /**
  50.      * Image resource
  51.      *
  52.      * @var resource 
  53.      */
  54.     private $_imageResource;
  55.  
  56.     /**
  57.      * Rendering function
  58.      *
  59.      * @var string 
  60.      */
  61.     private $_renderingFunction;
  62.  
  63.     /**
  64.      * Mime type
  65.      *
  66.      * @var string 
  67.      */
  68.     private $_mimeType;
  69.  
  70.     /**
  71.      * Unique name
  72.      *
  73.      * @var string 
  74.      */
  75.     private $_uniqueName;
  76.  
  77.     /**
  78.      * Create a new PHPExcel_Worksheet_MemoryDrawing
  79.      */
  80.     public function __construct()
  81.     {
  82.         // Initialise values
  83.         $this->_imageResource        null;
  84.         $this->_renderingFunction     self::RENDERING_DEFAULT;
  85.         $this->_mimeType            self::MIMETYPE_DEFAULT;
  86.         $this->_uniqueName            md5(rand(09999)time(rand(09999));
  87.  
  88.         // Initialize parent
  89.         parent::__construct();
  90.     }
  91.  
  92.     /**
  93.      * Get image resource
  94.      *
  95.      * @return resource 
  96.      */
  97.     public function getImageResource({
  98.         return $this->_imageResource;
  99.     }
  100.  
  101.     /**
  102.      * Set image resource
  103.      *
  104.      * @param    $value resource
  105.      * @return PHPExcel_Worksheet_MemoryDrawing 
  106.      */
  107.     public function setImageResource($value null{
  108.         $this->_imageResource $value;
  109.  
  110.         if (!is_null($this->_imageResource)) {
  111.             // Get width/height
  112.             $this->_width    = imagesx($this->_imageResource);
  113.             $this->_height    = imagesy($this->_imageResource);
  114.         }
  115.         return $this;
  116.     }
  117.  
  118.     /**
  119.      * Get rendering function
  120.      *
  121.      * @return string 
  122.      */
  123.     public function getRenderingFunction({
  124.         return $this->_renderingFunction;
  125.     }
  126.  
  127.     /**
  128.      * Set rendering function
  129.      *
  130.      * @param string $value 
  131.      * @return PHPExcel_Worksheet_MemoryDrawing 
  132.      */
  133.     public function setRenderingFunction($value PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT{
  134.         $this->_renderingFunction $value;
  135.         return $this;
  136.     }
  137.  
  138.     /**
  139.      * Get mime type
  140.      *
  141.      * @return string 
  142.      */
  143.     public function getMimeType({
  144.         return $this->_mimeType;
  145.     }
  146.  
  147.     /**
  148.      * Set mime type
  149.      *
  150.      * @param string $value 
  151.      * @return PHPExcel_Worksheet_MemoryDrawing 
  152.      */
  153.     public function setMimeType($value PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT{
  154.         $this->_mimeType $value;
  155.         return $this;
  156.     }
  157.  
  158.     /**
  159.      * Get indexed filename (using image index)
  160.      *
  161.      * @return string 
  162.      */
  163.     public function getIndexedFilename({
  164.         $extension     strtolower($this->getMimeType());
  165.         $extension     explode('/'$extension);
  166.         $extension     $extension[1];
  167.  
  168.         return $this->_uniqueName $this->getImageIndex('.' $extension;
  169.     }
  170.  
  171.     /**
  172.      * Get hash code
  173.      *
  174.      * @return string    Hash code
  175.      */
  176.     public function getHashCode({
  177.         return md5(
  178.               $this->_renderingFunction
  179.             . $this->_mimeType
  180.             . $this->_uniqueName
  181.             . parent::getHashCode()
  182.             . __CLASS__
  183.         );
  184.     }
  185.  
  186.     /**
  187.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  188.      */
  189.     public function __clone({
  190.         $vars get_object_vars($this);
  191.         foreach ($vars as $key => $value{
  192.             if (is_object($value)) {
  193.                 $this->$key clone $value;
  194.             else {
  195.                 $this->$key $value;
  196.             }
  197.         }
  198.     }
  199. }

Documentation generated on Sun, 27 Feb 2011 16:32:47 -0800 by phpDocumentor 1.4.3