/** * Displays image without saving and lose changes. * This method adds the Content-type HTTP header * * @access public * @param string $type Output format, default is the current used format * @param int $quality Image quality, default is 75 * @param int $expires Set Cache-Control and Expires of HTTP header * @return mixed True on success or a Jaws_Error object on error */ function display($type = '', $quality = null, $expires = 0) { if ($this->_readonly) { $result = parent::display($type, $quality, $expires); return $result; } $options = is_array($quality) ? $quality : array(); if (is_numeric($quality)) { $options['quality'] = $quality; } $quality = $this->_getOption('quality', $options, 75); $type = $type == 'jpg' ? 'jpeg' : $type; $type = strtolower($type == '' ? $this->_itype : $type); $type = empty($type) ? 'png' : $type; if (!$this->_typeSupported($type, 'w')) { return Jaws_Error::raiseError('Image type not supported for output.', __FUNCTION__); } if (!empty($expires)) { header("Cache-Control: max-age=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); } if (function_exists('imagealphablending')) { imagealphablending($this->_hImage, false); imagesavealpha($this->_hImage, true); } $funcName = 'image' . $type; header('Content-type: ' . image_type_to_mime_type($this->get_image_extension_to_type($type))); ob_start(); switch ($type) { case 'jpeg': $result = $funcName($this->_hImage, null, $quality); break; default: $result = $funcName($this->_hImage); } $content = ob_get_contents(); ob_end_clean(); $this->free(); if (!$result) { return Jaws_Error::raiseError('Couldn\'t display image', __FUNCTION__); } return $content; }
/** * Displays image without saving and lose changes. * This method adds the Content-type HTTP header * * @access public * @param string $type Output format, default is the current used format * @param int $quality Image quality, default is 75 * @param int $expires Set Cache-Control and Expires of HTTP header * @return mixed True on success or a Jaws_Error object on error */ function display($type = '', $quality = null, $expires = 0) { if ($this->_readonly) { $result = parent::display($type, $quality, $expires); return $result; } $options = is_array($quality) ? $quality : array(); if (is_numeric($quality)) { $options['quality'] = $quality; } $quality = $this->_getOption('quality', $options, 75); try { $this->_hImage->setImageCompression($quality); } catch (ImagickException $error) { return Jaws_Error::raiseError('Could not set image compression.', __FUNCTION__); } $type = $type == 'jpg' ? 'jpeg' : $type; $type = strtolower($type == '' ? $this->_itype : $type); $type = empty($type) ? 'png' : $type; try { $this->_hImage->setImageFormat($type); } catch (ImagickException $error) { return Jaws_Error::raiseError('Could not save image to file (conversion failed).', __FUNCTION__); } try { $result = $this->_hImage->getImageBlob(); } catch (ImagickException $error) { return Jaws_Error::raiseError('Could not display image.', __FUNCTION__); } if (!empty($expires)) { header("Cache-Control: max-age=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); } header('Content-type: ' . image_type_to_mime_type($this->get_image_extension_to_type($type))); $this->free(); return $result; }