web/lib/Zend/Pdf/Resource/ImageFactory.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Pdf
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: ImageFactory.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 
       
    23 /**
       
    24  * Zend_Pdf_ImageFactory
       
    25  *
       
    26  * Helps manage the diverse set of supported image file types.
       
    27  *
       
    28  * @package    Zend_Pdf
       
    29  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    31  * @todo       Use Zend_Mime not file extension for type determination.
       
    32  */
       
    33 class Zend_Pdf_Resource_ImageFactory
       
    34 {
       
    35     public static function factory($filename) {
       
    36         if(!is_file($filename)) {
       
    37             require_once 'Zend/Pdf/Exception.php';
       
    38             throw new Zend_Pdf_Exception("Cannot create image resource. File not found.");
       
    39         }
       
    40         $extension = pathinfo($filename, PATHINFO_EXTENSION);
       
    41         /*
       
    42          * There are plans to use Zend_Mime and not file extension. In the mean time, if you need to
       
    43          * use an alternate file extension just spin up the right processor directly.
       
    44          */
       
    45         switch (strtolower($extension)) {
       
    46             case 'tif':
       
    47                 //Fall through to next case;
       
    48             case 'tiff':
       
    49                 require_once 'Zend/Pdf/Resource/Image/Tiff.php';
       
    50                 return new Zend_Pdf_Resource_Image_Tiff($filename);
       
    51                 break;
       
    52             case 'png':
       
    53                 require_once 'Zend/Pdf/Resource/Image/Png.php';
       
    54                 return new Zend_Pdf_Resource_Image_Png($filename);
       
    55                 break;
       
    56             case 'jpg':
       
    57                 //Fall through to next case;
       
    58             case 'jpe':
       
    59                 //Fall through to next case;
       
    60             case 'jpeg':
       
    61                 require_once 'Zend/Pdf/Resource/Image/Jpeg.php';
       
    62                 return new Zend_Pdf_Resource_Image_Jpeg($filename);
       
    63                 break;
       
    64             default:
       
    65                 require_once 'Zend/Pdf/Exception.php';
       
    66                 throw new Zend_Pdf_Exception("Cannot create image resource. File extension not known or unsupported type.");
       
    67                 break;
       
    68         }
       
    69     }
       
    70 }
       
    71