本文整理匯總了PHP中Imagick::setImageCompression方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setImageCompression方法的具體用法?PHP Imagick::setImageCompression怎麽用?PHP Imagick::setImageCompression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::setImageCompression方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
function save($file_name = null, $quality = null)
{
$type = $this->out_type;
if (!$type) {
$type = $this->img_type;
}
if (!self::supportSaveType($type)) {
throw new lmbImageTypeNotSupportedException($type);
}
$this->img->setImageFormat($type);
$this->img->setImageFilename($file_name);
if (!is_null($quality) && strtolower($type) == 'jpeg') {
if (method_exists($this->img, 'setImageCompression')) {
$this->img->setImageCompression(imagick::COMPRESSION_JPEG);
$this->img->setImageCompressionQuality($quality);
} else {
$this->img->setCompression(imagick::COMPRESSION_JPEG);
$this->img->setCompressionQuality($quality);
}
}
if (!$this->img->writeImage($file_name)) {
throw new lmbImageSaveFailedException($file_name);
}
$this->destroyImage();
}
示例2: output
/**
* Outputs the image.
*
* @see XenForo_Image_Abstract::output()
*/
public function output($outputType, $outputFile = null, $quality = 85)
{
$this->_image->stripImage();
// NULL means output directly
switch ($outputType) {
case IMAGETYPE_GIF:
if (is_callable(array($this->_image, 'optimizeimagelayers'))) {
$this->_image->optimizeimagelayers();
}
$success = $this->_image->setImageFormat('gif');
break;
case IMAGETYPE_JPEG:
$success = $this->_image->setImageFormat('jpeg') && $this->_image->setImageCompression(Imagick::COMPRESSION_JPEG) && $this->_image->setImageCompressionQuality($quality);
break;
case IMAGETYPE_PNG:
$success = $this->_image->setImageFormat('png');
break;
default:
throw new XenForo_Exception('Invalid output type given. Expects IMAGETYPE_XXX constant.');
}
try {
if ($success) {
if (!$outputFile) {
echo $this->_image->getImagesBlob();
} else {
$success = $this->_image->writeImages($outputFile, true);
}
}
} catch (ImagickException $e) {
return false;
}
return $success;
}
示例3: watermarkPrint_imagick
private function watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo)
{
try {
// Open the original image
$img = new Imagick($src);
// Open the watermark
$watermark = new Imagick($watermark);
// Set transparency
if (strtoupper($watermark->getImageFormat()) !== 'PNG') {
$watermark->setImageOpacity($transparency / 100);
}
// Overlay the watermark on the original image
$img->compositeImage($watermark, imagick::COMPOSITE_OVER, $dest_x, $dest_y);
// Set quality
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setCompressionQuality($quality);
}
$result = $img->writeImage($src);
$img->clear();
$img->destroy();
$watermark->clear();
$watermark->destroy();
return $result ? true : false;
} catch (Exception $e) {
return false;
}
}
示例4: upload_image
function upload_image($arr_image, $location, $compression = null, $width = 245, $height = 170)
{
$image_location = "";
$allowedExts = array("gif", "jpeg", "jpg", "png", "JPG", "JPEG", "GIF", "PNG", "pdf", "PDF");
$temp = explode(".", $arr_image["file"]["name"]);
$extension = end($temp);
if (($arr_image["file"]["type"] == "image/gif" || $arr_image["file"]["type"] == "image/jpeg" || $arr_image["file"]["type"] == "image/jpg" || $arr_image["file"]["type"] == "image/pjpeg" || $arr_image["file"]["type"] == "image/x-png" || $arr_image["file"]["type"] == "image/png") && $arr_image["file"]["size"] < 1024 * 1000 * 10 && in_array($extension, $allowedExts)) {
if ($arr_image["file"]["error"] > 0) {
echo "Return Code: " . $arr_image["file"]["error"] . "<br>";
} else {
$compression_type = Imagick::COMPRESSION_JPEG;
$image_location = $location . "." . $extension;
if (move_uploaded_file($arr_image["file"]["tmp_name"], $image_location)) {
//echo "Image Uploaded to : ".$image_location;
} else {
//echo "Image not uploaded";
}
if (is_null($compression)) {
$im = new Imagick($image_location);
$im->setImageFormat('jpg');
$im->setImageCompression($compression_type);
$im->setImageCompressionQuality(95);
$im->stripImage();
$im->thumbnailImage($width, $height);
$image_location = $location . ".jpg";
$im->writeImage($image_location);
}
}
}
return $image_location;
}
示例5: display
/**
* 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);
$this->imagick->setImageCompression($quality);
if ($type && strcasecmp($type, $this->type)) {
try {
$this->imagick->setImageFormat($type);
} catch (ImagickException $e) {
return $this->raiseError('Could not save image to file (conversion failed).', IMAGE_TRANSFORM_ERROR_FAILED);
}
}
try {
$image = $this->imagick->getImageBlob();
} catch (ImagickException $e) {
return $this->raiseError('Could not display image.', IMAGE_TRANSFORM_ERROR_IO);
}
header('Content-type: ' . $this->getMimeType($type));
echo $image;
$this->free();
return true;
}
示例6: enhance
/**
* Do some tricks to cleanup and minimize the thumbnails size
*
* @param Imagick $image
*/
protected function enhance(\Imagick $image)
{
$image->setImageCompression(\Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(75);
$image->contrastImage(1);
$image->adaptiveBlurImage(1, 1);
$image->stripImage();
}
示例7: tinyJpeg
/**
* 處理圖片,不改變分辨率,減少圖片文件大小
* @param [string] $src 原圖路徑
* @param [int] [圖片質量]
* @param [string] $dest 目標圖路徑
* @return [void]
*/
public function tinyJpeg($src, $quality = 60, $dest)
{
$img = new Imagick();
$img->readImage($src);
$img->setImageCompression(Imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality($quality);
$img->stripImage();
$img->writeImage($dest);
$img->clear();
}
示例8: image
public function image($request_name, $extensions, $size, $throw = false)
{
$file_source = isset($_FILES[$request_name]) ? $_FILES[$request_name] : null;
if ($file_source == null) {
return false;
}
list($width, $height, $type) = getimagesize($file_source['tmp_name']);
if (isset($type) && !in_array($type, self::$image_types)) {
return false;
}
$ext = explode(".", $file_source["name"]);
$file_extension = strtolower(end($ext));
if (in_array($file_extension, $extensions) == false) {
return false;
}
if ($file_source['size'] > $size * 1024 * 1024) {
return false;
}
$file_name = $this->getRandomName();
$destination = self::UPLOADS_DIRECTORY . '/' . $file_name . '.' . $file_extension;
move_uploaded_file($file_source['tmp_name'], $destination);
if ($_GET['channel'] == self::CHANNEL_APP) {
$compression_type = Imagick::COMPRESSION_JPEG;
$thumbnail = new Imagick($destination);
$thumbnail->setImageCompression($compression_type);
$thumbnail->setImageCompressionQuality(75);
$thumbnail->stripImage();
$image_width = $thumbnail->getImageWidth();
$width = min($image_width, 800);
$thumbnail->thumbnailImage($width, null);
App_Controller_Site_Images::delete($destination);
$thumbnail->writeImage($destination);
}
$time = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$channel = self::CHANNEL_WEB;
if (isset($_GET['channel']) && ($_GET['channel'] == self::CHANNEL_APP || $_GET['channel'] == self::CHANNEL_WEB)) {
$channel = $_GET['channel'];
}
$query = "INSERT INTO `uploads` (`src`,`upload_time`,`token`,`ip`,`channel`) VALUES ('{$destination}','{$time}','{$file_name}','{$ip}','{$channel}')";
App_Db::getInstance()->getConn()->query($query);
return $file_name;
}
示例9: set_quality
/**
* Sets Image Compression quality on a 1-100% scale.
*
* @since 3.5.0
* @access public
*
* @param int $quality Compression Quality. Range: [1,100]
* @return true|WP_Error True if set successfully; WP_Error on failure.
*/
public function set_quality($quality = null)
{
$quality_result = parent::set_quality($quality);
if (is_wp_error($quality_result)) {
return $quality_result;
} else {
$quality = $this->get_quality();
}
try {
if ('image/jpeg' == $this->mime_type) {
$this->image->setImageCompressionQuality($quality);
$this->image->setImageCompression(imagick::COMPRESSION_JPEG);
} else {
$this->image->setImageCompressionQuality($quality);
}
} catch (Exception $e) {
return new WP_Error('image_quality_error', $e->getMessage());
}
return true;
}
示例10: imgThumbs
function imgThumbs($img)
{
if (file_exists($img)) {
$imagen = new Imagick($img);
if ($imagen->getImageHeight() <= $imagen->getImageWidth()) {
$imagen->resizeImage(120, 0, Imagick::FILTER_LANCZOS, 1);
} else {
$imagen->resizeImage(0, 120, Imagick::FILTER_LANCZOS, 1);
}
$imagen->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagen->setImageCompressionQuality(75);
$imagen->stripImage();
$imagen->writeImage($img);
$imagen->destroy();
chmod($img, 0777);
return true;
} else {
return false;
}
}
示例11: save
/**
* @param string $file
* @param int $quality
*
* @throws \ManaPHP\Image\Adapter\Exception
*/
public function save($file, $quality = 80)
{
$file = $this->alias->resolve($file);
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$this->_image->setFormat($ext);
if ($ext === 'gif') {
$this->_image->optimizeImageLayers();
} else {
if ($ext === 'jpg' || $ext === 'jpeg') {
$this->_image->setImageCompression(\Imagick::COMPRESSION_JPEG);
$this->_image->setImageCompressionQuality($quality);
}
}
$dir = dirname($file);
if (!@mkdir($dir, 0755, true) && !is_dir($dir)) {
throw new ImagickException('create `:dir` image directory failed: :message', ['dir' => $dir, 'message' => error_get_last()['message']]);
}
if (!$this->_image->writeImage($file)) {
throw new ImagickException('save `:file` image file failed', ['file' => $file]);
}
}
示例12: _prepare_image
/**
* Prepare the image for output, scaling and flattening as required
*
* @since 2.10
* @uses self::$image updates the image in this Imagick object
*
* @param integer zero or new width
* @param integer zero or new height
* @param boolean proportional fit (true) or exact fit (false)
* @param string output MIME type
* @param integer compression quality; 1 - 100
*
* @return void
*/
private static function _prepare_image($width, $height, $best_fit, $type, $quality)
{
if (is_callable(array(self::$image, 'scaleImage'))) {
if (0 < $width && 0 < $height) {
// Both are set; use them as-is
self::$image->scaleImage($width, $height, $best_fit);
} elseif (0 < $width || 0 < $height) {
// One is set; scale the other one proportionally if reducing
$image_size = self::$image->getImageGeometry();
if ($width && isset($image_size['width']) && $width < $image_size['width']) {
self::$image->scaleImage($width, 0);
} elseif ($height && isset($image_size['height']) && $height < $image_size['height']) {
self::$image->scaleImage(0, $height);
}
} else {
// Neither is specified, apply defaults
self::$image->scaleImage(150, 0);
}
}
if (0 < $quality && 101 > $quality) {
if ('image/jpeg' == $type) {
self::$image->setImageCompressionQuality($quality);
self::$image->setImageCompression(imagick::COMPRESSION_JPEG);
} else {
self::$image->setImageCompressionQuality($quality);
}
}
if ('image/jpeg' == $type) {
if (is_callable(array(self::$image, 'setImageBackgroundColor'))) {
self::$image->setImageBackgroundColor('white');
}
if (is_callable(array(self::$image, 'mergeImageLayers'))) {
self::$image = self::$image->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);
} elseif (is_callable(array(self::$image, 'flattenImages'))) {
self::$image = self::$image->flattenImages();
}
}
}
示例13: make_thumbnail_Imagick
private function make_thumbnail_Imagick($src_path, $width, $height, $dest)
{
$image = new Imagick($src_path);
# Select the first frame to handle animated images properly
if (is_callable(array($image, 'setIteratorIndex'))) {
$image->setIteratorIndex(0);
}
// устанавливаем качество
$format = $image->getImageFormat();
if ($format == 'JPEG' || $format == 'JPG') {
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
}
$image->setImageCompressionQuality(85);
$h = $image->getImageHeight();
$w = $image->getImageWidth();
// если не указана одна из сторон задаем ей пропорциональное значение
if (!$width) {
$width = round($w * ($height / $h));
}
if (!$height) {
$height = round($h * ($width / $w));
}
list($dx, $dy, $wsrc, $hsrc) = $this->crop_coordinates($height, $h, $width, $w);
// обрезаем оригинал
$image->cropImage($wsrc, $hsrc, $dx, $dy);
$image->setImagePage($wsrc, $hsrc, 0, 0);
// Strip out unneeded meta data
$image->stripImage();
// уменьшаем под размер
$image->scaleImage($width, $height);
$image->writeImage($dest);
chmod($dest, 0755);
$image->clear();
$image->destroy();
return true;
}
示例14: actionGo
public function actionGo()
{
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
$f = $_POST['filter'];
$capPhoto = $_POST['capPhoto'];
$min_rand = rand(0, 1000);
$max_rand = rand(100000000000, 10000000000000000);
$name_file = rand($min_rand, $max_rand);
//this part is for creating random name for image
$ext = end(explode(".", $_FILES["file"]["name"]));
//gets extension
$file = Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext;
move_uploaded_file($_FILES["file"]["tmp_name"], Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext);
chmod($file, 0777);
if (exif_imagetype($file) == IMAGETYPE_JPEG) {
$exif = exif_read_data($file);
if (isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if ($orientation == 6) {
$imz = new Imagick($file);
$imz->rotateimage("#FFF", 90);
$imz->writeImage($file);
chmod($file, 0777);
} else {
if ($orientation == 8) {
$imz = new Imagick($file);
$imz->rotateimage("#FFF", -90);
$imz->writeImage($file);
chmod($file, 0777);
}
}
}
}
// Max vert or horiz resolution
$maxsize = 1200;
// create new Imagick object
$image = new Imagick($file);
// Resizes to whichever is larger, width or height
if ($image->getImageHeight() <= $image->getImageWidth()) {
// Resize image using the lanczos resampling algorithm based on width
$image->resizeImage($maxsize, 0, Imagick::FILTER_LANCZOS, 1);
} else {
// Resize image using the lanczos resampling algorithm based on height
$image->resizeImage(0, $maxsize, Imagick::FILTER_LANCZOS, 1);
}
// Set to use jpeg compression
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
// Set compression level (1 lowest quality, 100 highest quality)
$image->setImageCompressionQuality(75);
// Strip out unneeded meta data
$image->stripImage();
// Writes resultant image to output directory
$image->writeImage($file);
// Destroys Imagick object, freeing allocated resources in the process
$image->destroy();
chmod($file, 0777);
$filter = Instagraph::factory($file, $file);
$filter->{$f}();
// 320 Show Preview
$immid = new Imagick($file);
if ($immid->getimagewidth() > 320) {
$immid->thumbnailImage(320, null);
$immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext);
$immid->destroy();
chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777);
} else {
$immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext);
$immid->destroy();
chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777);
}
// null x 230 show last upload
$imlast = new Imagick($file);
$imlast->thumbnailimage(null, 230);
$imlast->writeImage(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext);
$imlast->destroy();
chmod(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext, 0777);
// 130 x 110 thumbmail
$im = new Imagick($file);
$im->thumbnailImage(130, 110);
$im->writeImage(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext);
chmod(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext, 0777);
$im->destroy();
$photo = new Photo();
$photo->link = $file;
$photo->fbid = Yii::app()->facebook->getUser();
$photo->ip = $_SERVER['REMOTE_ADDR'];
if ($photo->save()) {
$id = $photo->id;
if (isset($_POST['shareFB'])) {
$share = 1;
} else {
$share = 0;
}
if ($share == 1) {
$cr = "\n" . "http://www.pla2gram.com/?p=" . $id . "&theater=1";
$capFB = $capPhoto . $cr;
// Post to Facebook
$args = array('message' => $capFB);
//.........這裏部分代碼省略.........
示例15: switch
switch ($_POST['compression']) {
case 'low':
$cq = 80;
break;
case 'medium':
$cq = 65;
break;
case 'high':
$cq = 50;
break;
default:
$cq = 100;
break;
}
$image->setImageFormat('jpeg');
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality($cq);
} else {
$image->setImageFormat('png');
$compress[] = $file;
}
if (isset($size[SPLASH_ROTATE])) {
$image->rotateImage(new ImagickPixel('none'), $size[SPLASH_ROTATE]);
}
$image->cropThumbnailImage($size[SPLASH_WIDTH], $size[SPLASH_HEIGHT]);
$image->setImageResolution($size[SPLASH_DPI], $size[SPLASH_DPI]);
$image->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$image->writeImage($file);
}
}
if ($_POST['compression'] && count($compress) > 0) {