1: <?php
2: /**
3: * The Horde_Mime_Viewer_Images class allows images to be displayed.
4: *
5: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @category Horde
12: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
13: * @package Mime_Viewer
14: */
15: class Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Base
16: {
17: /**
18: * This driver's display capabilities.
19: *
20: * @var array
21: */
22: protected $_capability = array(
23: 'full' => true,
24: 'info' => false,
25: 'inline' => false,
26: 'raw' => false
27: );
28:
29: /**
30: * Constructor.
31: *
32: * @param Horde_Mime_Part $mime_part The object with the data to be
33: * rendered.
34: * @param array $conf Configuration.
35: */
36: public function __construct(Horde_Mime_Part $part, array $conf = array())
37: {
38: parent::__construct($part, $conf);
39:
40: /* TODO: Are there other image types that are compressed? */
41: $this->_metadata['compressed'] = in_array($this->_getType(), array('image/gif', 'image/jpeg', 'image/png'));
42: }
43:
44: /**
45: * Return the full rendered version of the Horde_Mime_Part object.
46: *
47: * @return array See parent::render().
48: */
49: protected function _render()
50: {
51: return $this->_renderReturn(null, $this->_getType());
52: }
53:
54: /**
55: * Return the content-type to use for the image.
56: *
57: * @return string The content-type of the image.
58: */
59: protected function _getType()
60: {
61: $type = $this->_mimepart->getType();
62:
63: switch ($type) {
64: case 'image/jpg':
65: /* image/jpg == image/jpeg. */
66: case 'image/pjpeg':
67: /* image/jpeg and image/pjpeg *appear* to be the same entity, but
68: * Mozilla (for one) don't seem to want to accept the latter. */
69: return 'image/jpeg';
70:
71: case 'image/x-png':
72: /* image/x-png == image/png. */
73: return 'image/png';
74:
75: default:
76: return $type;
77: }
78: }
79:
80: }
81: