ImageFactory.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** Zend_Pdf */
  22. require_once 'Zend/Pdf.php';
  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-2009 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. throw new Zend_Pdf_Exception("Cannot create image resource. File not found.");
  38. }
  39. $extension = pathinfo($filename, PATHINFO_EXTENSION);
  40. /*
  41. * There are plans to use Zend_Mime and not file extension. In the mean time, if you need to
  42. * use an alternate file extension just spin up the right processor directly.
  43. */
  44. switch (strtolower($extension)) {
  45. case 'tif':
  46. //Fall through to next case;
  47. case 'tiff':
  48. return new Zend_Pdf_Resource_Image_Tiff($filename);
  49. break;
  50. case 'png':
  51. return new Zend_Pdf_Resource_Image_Png($filename);
  52. break;
  53. case 'jpg':
  54. //Fall through to next case;
  55. case 'jpe':
  56. //Fall through to next case;
  57. case 'jpeg':
  58. return new Zend_Pdf_Resource_Image_Jpeg($filename);
  59. break;
  60. default:
  61. throw new Zend_Pdf_Exception("Cannot create image resource. File extension not known or unsupported type.");
  62. break;
  63. }
  64. }
  65. }