/** * Displays image without saving and lose changes * * This method adds the Content-type HTTP header * * @param string type (JPG,PNG...); * @param int quality 75 * * @return bool|PEAR_Error TRUE or a PEAR_Error object on error * @access public */ function display($type = '', $quality = null) { $options = is_array($quality) ? $quality : array(); if (is_numeric($quality)) { $options['quality'] = $quality; } $quality = $this->_getOption('quality', $options, 75); imagick_setcompressionquality($this->imageHandle, $quality); if ($type && strcasecomp($type, $this->type) && !imagick_convert($this->imageHandle, $type)) { return $this->raiseError('Couldn\'t save image to file (conversion failed).', IMAGE_TRANSFORM_ERROR_FAILED); } if (!($image = imagick_image2blob($this->imageHandle))) { return $this->raiseError('Couldn\'t display image.', IMAGE_TRANSFORM_ERROR_IO); } header('Content-type: ' . imagick_getmimetype($this->imageHandle)); echo $image; $this->free(); return true; }
/** * Save the image file * * @param $filename string the name of the file to write to * * @return none */ function save($filename, $type = '', $quality = 75) { if (function_exists('imagick_setcompressionquality')) { imagick_setcompressionquality($this->imageHandle, $quality); } if ($type != '') { $type = strtoupper($type); imagick_write($this->imageHandle, $filename, $type); } else { imagick_write($this->imageHandle, $filename); } imagick_free($handle); }