本文整理匯總了PHP中Imagick::setCompression方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setCompression方法的具體用法?PHP Imagick::setCompression怎麽用?PHP Imagick::setCompression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::setCompression方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: IMAGEN_tipo_normal
function IMAGEN_tipo_normal()
{
$escalado = 'IMG/i/m/' . $_GET['ancho'] . '_' . $_GET['alto'] . '_' . $_GET['sha1'];
$origen = 'IMG/i/' . $_GET['sha1'];
$ancho = $_GET['ancho'];
$alto = $_GET['alto'];
if (@($ancho * $alto) > 562500) {
die('La imagen solicitada excede el límite de este servicio');
}
if (!file_exists($escalado)) {
$im = new Imagick($origen);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(85);
$im->setImageFormat('jpeg');
$im->stripImage();
$im->despeckleImage();
$im->sharpenImage(0.5, 1);
//$im->reduceNoiseImage(0);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->resizeImage($ancho, $alto, imagick::FILTER_LANCZOS, 1);
$im->writeImage($escalado);
$im->destroy();
}
$im = new Imagick($escalado);
$output = $im->getimageblob();
$outputtype = $im->getFormat();
$im->destroy();
header("Content-type: {$outputtype}");
header("Content-length: " . filesize($escalado));
echo $output;
}
示例2: run
public function run($file, $temp_dir)
{
$info = $this->getImageDetails($file);
$image = new Imagick();
$image->readImage($file);
if ($info['ext'] == 'jpg') {
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setCompressionQuality($this->settings['quality']);
$image->setImageFormat('jpeg');
}
if ($info['ext'] == 'gif') {
//remove the canvas (for .gif)
$image->setImagePage(0, 0, 0, 0);
}
//crop and resize the image
$image->resizeImage($this->settings['width'], $this->settings['height'], Imagick::FILTER_LANCZOS, 1, true);
$image->writeImage($file);
return TRUE;
}
示例3: 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();
}
示例4: softThumb
public function softThumb($width, $height, $path, $bg = 'transparent')
{
if ($this->originImage) {
echo "\nWrite image to `{$path}`\n";
$resizeParams = $this->getSizes($width, $height);
$overlay = clone $this->originImage;
$overlay->scaleImage($resizeParams['width'], $resizeParams['height']);
$overlayGeo = $overlay->getImageGeometry();
if ($overlayGeo['width'] > $overlayGeo['height']) {
$resizeParams['top'] = ($height - $overlayGeo['height']) / 2;
$resizeParams['left'] = 0;
} else {
$resizeParams['top'] = 0;
$resizeParams['left'] = ($width - $overlayGeo['width']) / 2;
}
$thumb = new \Imagick();
$thumb->newImage($width, $height, $bg);
$thumb->setImageFormat("png");
$thumb->setCompression(\Imagick::COMPRESSION_ZIP);
$thumb->setImageCompressionQuality(0);
$thumb->compositeImage($overlay, \Imagick::COMPOSITE_DEFAULT, $resizeParams['left'], $resizeParams['top']);
$thumb->writeImageFile(fopen($path, "wb"));
$thumb->destroy();
} else {
throw new \Exception("As first You must load image", 404);
}
}
示例5: setFile
/**
* Associates the model with the file
* @param string $filePath
* @return boolean
*/
public function setFile($filePath)
{
if (!file_exists($filePath)) {
return false;
}
$info = getimagesize($filePath);
$imageWidth = $info[0];
$imageHeight = $info[1];
$image = new Imagick();
$image->readimage($filePath);
$image->setResourceLimit(Imagick::RESOURCETYPE_MEMORY, 1);
$maxSize = 1920;
if ($imageWidth > $maxSize && $imageWidth > $imageHeight) {
$image->thumbnailimage($maxSize, null);
} elseif ($imageHeight > $maxSize && $imageHeight > $imageWidth) {
$image->thumbnailimage(null, $maxSize);
}
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setCompressionQuality(80);
$image->stripimage();
$this->size = filesize($filePath);
$this->type = $info['mime'];
$this->width = $info[0];
$this->height = $info[1];
$this->content = $image->getImageBlob();
$this->expireAt(time() + static::EXP_DAY);
return true;
}
示例6: _imageResizeAndSave
protected function _imageResizeAndSave($object)
{
$path = APPLICATION_ROOT . '/public_html/images/topcontentblock/';
$system->lng = $this->_getParam('lng');
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($path);
$adapter->setOptions(array('ignoreNoFile' => true));
if (!$adapter->receive()) {
$msgr = Sanmax_MessageStack::getInstance('SxModule_Topcontentblock_Validator');
$msgr->addMessage('file', $adapter->getMessages(), 'title');
}
if ($object->getPicture() == null) {
$object->setPicture('');
}
$files = $adapter->getFileInfo();
foreach ($files as $file) {
if (!$file['tmp_name']) {
continue;
}
$path0 = $path . "253X115/";
$path1 = $path . "1263X575/";
$path2 = $path . "1263X325/";
$filename = $object->createThumbName($file['name']) . '_' . time() . '.jpg';
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(253, 115);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(100);
$image->setImageFormat('jpeg');
$image->writeImage($path0 . $filename);
$image->clear();
$image->destroy();
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(1263, 575);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(75);
$image->setImageFormat('jpeg');
$image->writeImage($path1 . $filename);
$image->clear();
$image->destroy();
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(1263, 325);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(75);
$image->setImageFormat('jpeg');
$image->writeImage($path2 . $filename);
$image->clear();
$image->destroy();
unlink($file['tmp_name']);
$object->setPicture($filename);
}
}
示例7: _imageResizeAndSave
protected function _imageResizeAndSave($object)
{
$path = APPLICATION_ROOT . '/public_html/images/eyecatchers/';
$system->lng = $this->_getParam('lng');
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($path);
$adapter->setOptions(array('ignoreNoFile' => true));
if (!$adapter->receive()) {
$msgr = Sanmax_MessageStack::getInstance('SxModule_Eyecatchers_Validator');
$msgr->addMessage('file', $adapter->getMessages(), 'title');
}
if ($object->getPicture() == null) {
$object->setPicture('');
}
$files = $adapter->getFileInfo();
foreach ($files as $file) {
if (!$file['tmp_name']) {
continue;
}
$path0 = $path . "253x115/";
$path1 = $path . "980x450/";
if (!is_dir($path0)) {
mkdir($path0, 0777, true);
}
if (!is_dir($path1)) {
mkdir($path1, 0777, true);
}
$filename = $object->createThumbName($file['name']) . '_' . time() . '.png';
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(253, 115);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(100);
$image->setBackgroundColor(new ImagickPixel('transparent'));
$image->setImageFormat('png32');
$image->writeImage($path0 . $filename);
$image->clear();
$image->destroy();
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(980, 450);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(75);
$image->setBackgroundColor(new ImagickPixel('transparent'));
$image->setImageFormat('png32');
$image->writeImage($path1 . $filename);
$image->clear();
$image->destroy();
unlink($file['tmp_name']);
$object->setPicture($filename);
}
}
示例8: handleSave
/**
* @param Asset $asset
* @return string
*/
public function handleSave(Asset $asset)
{
$newImage = new \Imagick($asset->getUploadedFile()->getRealPath());
$asset->setHeight($newImage->getImageHeight());
$asset->setWidth($newImage->getImageWidth());
/** @var array $requiredImage */
foreach ($this->requiredImages as $requiredImage) {
$newImage = new \Imagick($asset->getUploadedFile()->getRealPath());
$newFilename = pathinfo($asset->getFilename(), PATHINFO_FILENAME) . '-' . $requiredImage['name'] . '.' . pathinfo($asset->getFilename(), PATHINFO_EXTENSION);
$imageWidth = $newImage->getImageWidth();
$imageHeight = $newImage->getImageHeight();
$isLandscapeFormat = $imageWidth > $imageHeight;
$orientation = $newImage->getImageOrientation();
$newImage->setCompression(\Imagick::COMPRESSION_JPEG);
$newImage->setImageCompressionQuality($requiredImage['quality']);
if ($isLandscapeFormat) {
$desiredWidth = $requiredImage['long'];
$newImage->resizeImage($desiredWidth, 0, \Imagick::FILTER_LANCZOS, 1);
if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) {
$newImage->cropImage($desiredWidth, $requiredImage['short'], 0, 0);
} else {
$newImage->resizeImage(0, $requiredImage['short'], \Imagick::FILTER_LANCZOS, 1);
}
} else {
$desiredHeight = $requiredImage['long'];
$newImage->resizeImage(0, $desiredHeight, \Imagick::FILTER_LANCZOS, 1);
if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) {
$newImage->cropImage($requiredImage['short'], $desiredHeight, 0, 0);
} else {
$newImage->resizeImage($requiredImage['short'], 0, \Imagick::FILTER_LANCZOS, 1);
}
}
/**
* This unfortunately kills the orientation. Leave EXIF-Info for now.
*
* $newImage->stripImage();
* $newImage->setImageOrientation($orientation);
*/
$this->assetStorage->uploadFile($newFilename, $newImage);
$subAsset = new SubAsset();
$subAsset->setFilename($newFilename);
$subAsset->setType($requiredImage['name']);
$subAsset->setHeight($newImage->getImageHeight());
$subAsset->setWidth($newImage->getImageWidth());
$asset->addSubAsset($subAsset);
}
}
示例9: storeBase64Image
public function storeBase64Image($name, $dir, $fileContentBase64)
{
$uploadDir = $this->rootDir . '/../web' . $dir;
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$image = new \Imagick();
$data = explode(',', $fileContentBase64);
$fileContent = base64_decode($data[1]);
$image->readImageBlob($fileContent);
$filename = $name . "." . time() . '.jpg';
$image->setImageFormat('jpeg');
$image->setCompression(\Imagick::COMPRESSION_JPEG);
$image->setCompressionQuality(50);
$image->writeImage($uploadDir . $filename);
return $filename;
}
示例10: convertImage
/**
* Converts the background image to the correct type and quality
* @param $filename
*/
protected function convertImage($filename, $bookHeight, $bookWidth)
{
if ($this->backgroundImageType == 'png') {
return $filename;
}
$newFilename = substr($filename, 0, -4) . '.jpg';
$img = new Imagick($filename);
$img->setformat('jpeg');
$img->setCompression(imagick::COMPRESSION_JPEG);
if ($this->backgroundResize) {
$img->resizeImage($bookWidth, $bookHeight, Imagick::FILTER_LANCZOS, 1);
}
$img->writeimage($newFilename);
return $newFilename;
}
示例11: doUpload
public function doUpload($key, $sw = 0, $sh = 0)
{
$config = Zend_Registry::get('config');
if (array_key_exists($key, $_FILES) && $_FILES[$key]['size']) {
try {
$image = new Imagick();
$image->readImageBlob(file_get_contents($_FILES[$key]['tmp_name']));
$iw = $image->getImageWidth();
$ih = $image->getImageHeight();
$uniqid = uniqid('', true);
$path_n = APPLICATION_PATH . "/images/thumbnail/" . $uniqid . ".jpg";
$url_n = $config->app->base_url . "/images/thumbnail/" . $uniqid . ".jpg";
if ($sw == 0 && $sh == 0) {
$sw = $iw;
$sh = $ih;
$path_n = APPLICATION_PATH . "/images/" . $uniqid . ".jpg";
$url_n = $config->app->base_url . "/images/" . $uniqid . ".jpg";
}
if ($sw == $iw && $sh == $ih) {
$fh = fopen($path_n, 'wb');
fwrite($fh, $image->getImagesBlob());
fclose($fh);
} elseif ($sw / $iw > $sh / $ih) {
$ww = intval($iw * $sh / $ih);
$hh = intval($ih * $sw / $iw);
$image->scaleImage($sw, $hh);
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, 0, intval(($sh - $hh) / 2));
$im2->setImageFormat('jpeg');
$fh = fopen($path_n, 'wb');
fwrite($fh, $im2->getImagesBlob());
fclose($fh);
} else {
$ww = intval($iw * $sh / $ih);
$hh = intval($ih * $sw / $iw);
if ($sw == 0 && $sh == 0) {
$ww = 1;
$hh = 1;
$image->scaleImage($ww, $sh);
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, intval(($sw - $ww) / 2), 0);
$im2->setImageFormat('jpeg');
} else {
//for thumbnail set compression to 90
$image->scaleImage($ww, $sh);
$im2 = new Imagick();
$im2->setCompression(Imagick::COMPRESSION_JPEG);
$im2->setCompressionQuality(90);
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, intval(($sw - $ww) / 2), 0);
$im2->setImageFormat('jpeg');
}
/*
$image->scaleImage($ww, $sh);
$im2 = new Imagick();
$im2->newImage($sw, $sh, "none");
$im2->compositeImage($image, Imagick::COMPOSITE_DEFAULT, intval(($sw - $ww) / 2), 0);
$im2->setImageFormat('jpeg');
*/
$fh = fopen($path_n, 'wb');
fwrite($fh, $im2->getImagesBlob());
fclose($fh);
}
return $url_n;
} catch (Exception $e) {
return null;
}
} else {
return null;
}
}
示例12: cratePDFThumbnail
/**
* Creates PDF document thumbnail
* @param $docPath
* @param $thumbDirectory
* @param $docId
* @param int $thumbsizeX
* @param int $thumbsizeY
* @return bool|string
*/
public static function cratePDFThumbnail($docPath, $thumbDirectory, $docId, $thumbsizeX = 400, $thumbsizeY = 600, $batch=false)
{
$imagesPath = Yii::getPathOfAlias('webroot') . '/protected/data/'; // Path to your images directory on the server
$thumbsPath = $imagesPath . $thumbDirectory; // Path to image thumbnails directory
$temp_file_path = $thumbsPath . '/' . ($batch ? 'batch_' : '') . $docId ;
/* Pdf convertion Variant 1*/
$im = new Imagick(Yii::getPathOfAlias('webroot') . '/' . $docPath);
$im->setImageColorspace(255);
$im->setResolution($thumbsizeX, $thumbsizeY);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(60);
$im->setImageFormat('jpeg');
$im->writeImage($temp_file_path);
$im->clear();
$im->destroy();
/*
* Pdf convertion Variant 2 Works with better quality. Needs exec rights and
**/
/*$path_to_extracted_file = Yii::getPathOfAlias('webroot') . '/' . $docPath;
exec('pdftoppm '.$path_to_extracted_file.' -jpeg -scale-to-x 600 -scale-to-y -1 '.$temp_file_path);
$temp_file_path=$temp_file_path.'-1.jpg';
exec('chmod 755 '. $temp_file_path);
*/
// A little error-checking overkill
if (!file_exists($temp_file_path)) {
return false;
} else {
return $temp_file_path;
}
}
示例13: _imageResizeAndSave
protected function _imageResizeAndSave($object)
{
$path = APPLICATION_ROOT . '/public_html/images/events/';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($path);
$adapter->setOptions(array('ignoreNoFile' => true));
if (!$adapter->receive()) {
$msgr = Sanmax_MessageStack::getInstance('SxModule_News_Validator');
$msgr->addMessage('file', $adapter->getMessages(), 'title');
}
if ($object->getImage() == null) {
$object->setImage('');
}
$files = $adapter->getFileInfo();
foreach ($files as $file) {
if (!$file['tmp_name']) {
continue;
}
$path0 = $path . "280x160/";
if (!is_dir($path0)) {
mkdir($path0, 0777, true);
}
$path1 = $path . "630x355/";
if (!is_dir($path1)) {
mkdir($path1, 0777, true);
}
$filename = $object->createThumbName($file['name']) . '_' . time() . '.jpg';
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(280, 160);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(80);
$image->setImageFormat('jpeg');
$image->writeImage($path0 . $filename);
$image->clear();
$image->destroy();
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(630, 355);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(80);
$image->setImageFormat('jpeg');
$image->writeImage($path1 . $filename);
$image->clear();
$image->destroy();
unlink($file['tmp_name']);
$object->setImage($filename);
}
}
示例14: Imagen__CrearMiniatura
function Imagen__CrearMiniatura($Origen, $Destino, $Ancho = 100, $Alto = 100)
{
$im = new Imagick($Origen);
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(80);
$im->setImageFormat('jpeg');
list($newX, $newY) = scaleImage($im->getImageWidth(), $im->getImageHeight(), $Ancho, $Alto);
$im->thumbnailImage($newX, $newY, false);
return $im->writeImage($Destino);
}
示例15: reduire_image
function reduire_image($userfile_name)
{
global $pmb_vignette_x;
global $pmb_vignette_y;
global $base_path;
global $pmb_curl_available;
if (!$pmb_vignette_x) {
$pmb_vignette_x = 100;
}
if (!$pmb_vignette_y) {
$pmb_vignette_y = 100;
}
$src_image = '';
if (file_exists("{$base_path}/temp/{$userfile_name}")) {
$bidon = "{$base_path}/temp/{$userfile_name}";
$source_file = $bidon . "[0]";
} else {
$bidon = $userfile_name;
//Il s'agit d'une url, on copie le fichier en local
$nom_temp = session_id() . microtime();
$nom_temp = str_replace(' ', '_', $nom_temp);
$nom_temp = str_replace('.', '_', $nom_temp);
$fichier_tmp = "{$base_path}/temp/" . $nom_temp;
if ($pmb_curl_available) {
$aCurl = new Curl();
$aCurl->save_file_name = $fichier_tmp;
$aCurl->get($userfile_name);
} else {
$handle = fopen($userfile_name, "rb");
$filecontent = stream_get_contents($handle);
fclose($handle);
$fd = fopen($fichier_tmp, "w");
fwrite($fd, $filecontent);
fclose($fd);
}
$source_file = $fichier_tmp . "[0]";
}
$error = true;
if (extension_loaded('imagick')) {
mysql_set_wait_timeout(3600);
$error = false;
try {
$img = new Imagick();
$img->readImage($source_file);
if ($img->getImageWidth() > $pmb_vignette_x || $img->getImageHeight() > $pmb_vignette_y) {
// Si l'image est trop grande on la réduit
$img->thumbnailimage($pmb_vignette_x, $pmb_vignette_y, true);
}
$img->setImageFormat("png");
$img->setCompression(Imagick::COMPRESSION_LZW);
$img->setCompressionQuality(90);
$contenu_vignette = $img->getImageBlob();
} catch (Exception $ex) {
$error = true;
}
unlink($fichier_tmp);
}
if ($error) {
$size = @getimagesize($bidon);
/* ".gif"=>"1",
".jpg"=>"2",
".jpeg"=>"2",
".png"=>"3",
".swf"=>"4",
".psd"=>"5",
".bmp"=>"6");
*/
switch ($size[2]) {
case 1:
$src_img = imagecreatefromgif($bidon);
break;
case 2:
$src_img = imagecreatefromjpeg($bidon);
break;
case 3:
$src_img = imagecreatefrompng($bidon);
break;
case 6:
$src_img = imagecreatefromwbmp($bidon);
break;
default:
break;
}
$erreur_vignette = 0;
if ($src_img) {
$rs = $pmb_vignette_x / $pmb_vignette_y;
$taillex = imagesx($src_img);
$tailley = imagesy($src_img);
if (!$taillex || !$tailley) {
return "";
}
if ($taillex > $pmb_vignette_x || $tailley > $pmb_vignette_y) {
$r = $taillex / $tailley;
if ($r < 1 && $rs < 1) {
//Si x plus petit que y et taille finale portrait
//Si le format final est plus large en proportion
if ($rs > $r) {
$new_h = $pmb_vignette_y;
$new_w = $new_h * $r;
} else {
//.........這裏部分代碼省略.........