예제 #1
0
파일: GD.php 프로젝트: juniortux/jaws
 /**
  * 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;
 }
예제 #2
0
파일: Imagick.php 프로젝트: Dulciane/jaws
 /**
  * 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;
 }