1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Document
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * DocumentImage class, provides an easy interface to output image data
14 *
15 * @since 12.1
16 */
17 class JDocumentImage extends JDocument
18 {
19 /**
20 * Class constructor
21 *
22 * @param array $options Associative array of options
23 *
24 * @since 12.1
25 */
26 public function __construct($options = array())
27 {
28 parent::__construct($options);
29
30 // Set mime type
31 $this->_mime = 'image/png';
32
33 // Set document type
34 $this->_type = 'image';
35 }
36
37 /**
38 * Render the document.
39 *
40 * @param boolean $cache If true, cache the output
41 * @param array $params Associative array of attributes
42 *
43 * @return The rendered data
44 *
45 * @since 12.1
46 */
47 public function render($cache = false, $params = array())
48 {
49 // Get the image type
50 $type = JFactory::getApplication()->input->get('type', 'png');
51
52 switch ($type)
53 {
54 case 'jpg':
55 case 'jpeg':
56 $this->_mime = 'image/jpeg';
57 break;
58 case 'gif':
59 $this->_mime = 'image/gif';
60 break;
61 case 'png':
62 default:
63 $this->_mime = 'image/png';
64 break;
65 }
66
67 $this->_charset = null;
68
69 parent::render();
70
71 return $this->getBuffer();
72 }
73 }
74