2
0

ImageFactory.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @package Zend_Pdf
  16. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  17. * @license http://framework.zend.com/license/new-bsd New BSD License
  18. */
  19. /** Zend_Pdf */
  20. require_once 'Zend/Pdf.php';
  21. /**
  22. * Zend_Pdf_ImageFactory
  23. *
  24. * Helps manage the diverse set of supported image file types.
  25. *
  26. * @package Zend_Pdf
  27. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @todo Use Zend_Mime not file extension for type determination.
  30. */
  31. class Zend_Pdf_Resource_ImageFactory
  32. {
  33. public static function factory($filename) {
  34. if(!is_file($filename)) {
  35. throw new Zend_Pdf_Exception("Cannot create image resource. File not found.");
  36. }
  37. $extension = pathinfo($filename, PATHINFO_EXTENSION);
  38. /*
  39. * There are plans to use Zend_Mime and not file extension. In the mean time, if you need to
  40. * use an alternate file extension just spin up the right processor directly.
  41. */
  42. switch (strtolower($extension)) {
  43. case 'tif':
  44. //Fall through to next case;
  45. case 'tiff':
  46. return new Zend_Pdf_Resource_Image_Tiff($filename);
  47. break;
  48. case 'png':
  49. return new Zend_Pdf_Resource_Image_Png($filename);
  50. break;
  51. case 'jpg':
  52. //Fall through to next case;
  53. case 'jpe':
  54. //Fall through to next case;
  55. case 'jpeg':
  56. return new Zend_Pdf_Resource_Image_Jpeg($filename);
  57. break;
  58. default:
  59. throw new Zend_Pdf_Exception("Cannot create image resource. File extension not known or unsupported type.");
  60. break;
  61. }
  62. }
  63. }