File indexing completed on 2024-12-22 05:36:56

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 
0023 /**
0024  * Zend_Pdf_ImageFactory
0025  *
0026  * Helps manage the diverse set of supported image file types.
0027  *
0028  * @package    Zend_Pdf
0029  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0030  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0031  * @todo       Use Zend_Mime not file extension for type determination.
0032  */
0033 class Zend_Pdf_Resource_ImageFactory
0034 {
0035     public static function factory($filename) {
0036         if(!is_file($filename)) {
0037             // require_once 'Zend/Pdf/Exception.php';
0038             throw new Zend_Pdf_Exception("Cannot create image resource. File not found.");
0039         }
0040         $extension = pathinfo($filename, PATHINFO_EXTENSION);
0041         /*
0042          * There are plans to use Zend_Mime and not file extension. In the mean time, if you need to
0043          * use an alternate file extension just spin up the right processor directly.
0044          */
0045         switch (strtolower($extension)) {
0046             case 'tif':
0047                 //Fall through to next case;
0048             case 'tiff':
0049                 // require_once 'Zend/Pdf/Resource/Image/Tiff.php';
0050                 return new Zend_Pdf_Resource_Image_Tiff($filename);
0051                 break;
0052             case 'png':
0053                 // require_once 'Zend/Pdf/Resource/Image/Png.php';
0054                 return new Zend_Pdf_Resource_Image_Png($filename);
0055                 break;
0056             case 'jpg':
0057                 //Fall through to next case;
0058             case 'jpe':
0059                 //Fall through to next case;
0060             case 'jpeg':
0061                 // require_once 'Zend/Pdf/Resource/Image/Jpeg.php';
0062                 return new Zend_Pdf_Resource_Image_Jpeg($filename);
0063                 break;
0064             default:
0065                 // require_once 'Zend/Pdf/Exception.php';
0066                 throw new Zend_Pdf_Exception("Cannot create image resource. File extension not known or unsupported type.");
0067                 break;
0068         }
0069     }
0070 }
0071