本文整理汇总了PHP中imagick::setImageCompressionQuality方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::setImageCompressionQuality方法的具体用法?PHP imagick::setImageCompressionQuality怎么用?PHP imagick::setImageCompressionQuality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagick
的用法示例。
在下文中一共展示了imagick::setImageCompressionQuality方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processPdf
public function processPdf($fileNames)
{
$mpdf = Yii::app()->ePdf->mpdf();
$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile('../' . $fileNames['pdf']);
if ($pagecount > 3) {
for ($i = 1; $i <= 3; $i++) {
if ($i != 1) {
$mpdf->AddPage();
}
$import_page = $mpdf->ImportPage($i);
// add last 3 page
$mpdf->UseTemplate($import_page);
}
} else {
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);
}
$mpdf->Output('../' . Extensions::FILE_PDF_PREVIEW_PATH . $fileNames['pdfPreview'], 'F');
$im = new imagick();
$im->readimage('/home/notesgen/public_html/' . Extensions::FILE_PDF_PREVIEW_PATH . $fileNames['pdfPreview']);
$im->setImageCompressionQuality(0);
$im->setImageFormat('jpeg');
$im->writeImage('../' . Extensions::FILE_IMAGE_PATH . $fileNames['image']);
$im->setImageCompressionQuality(80);
$im->writeImage('../' . Extensions::FILE_IMAGE_PATH_APP . $fileNames['image']);
$im->clear();
$im->destroy();
}
示例2: generatePdfImages
public function generatePdfImages($fileName, $filePages)
{
$pages = 0;
$json = array();
if (file_exists(DIR_DOWNLOAD . $this->config->get('msconf_temp_download_path') . $fileName)) {
if (preg_match('/[^-0-9,]/', $filePages)) {
$json['errors'][] = $this->language->get('ms_error_product_invalid_pdf_range');
} else {
$offsets = explode(',', $filePages);
foreach ($offsets as $offset) {
if (!preg_match('/^[0-9]+(-[0-9]+)?$/', $offset)) {
$json['errors'][] = $this->language->get('ms_error_product_invalid_pdf_range');
break;
}
}
}
if (!empty($json['errors'])) {
return $json;
}
$pathinfo = pathinfo(DIR_DOWNLOAD . $this->config->get('msconf_temp_download_path') . $fileName);
$list = glob(DIR_IMAGE . $this->config->get('msconf_temp_image_path') . $pathinfo['filename'] . '*\\.png');
//var_dump($list);
foreach ($list as $pagePreview) {
//var_dump('unlinking ' . $pagePreview);
@unlink($pagePreview);
}
$name = DIR_DOWNLOAD . $this->config->get('msconf_temp_download_path') . $fileName . "[" . $filePages . "]";
$im = new imagick($name);
$pages = $im->getNumberImages();
$im->setImageFormat("png");
$im->setImageCompressionQuality(100);
$pathinfo = pathinfo(DIR_DOWNLOAD . $this->config->get('msconf_temp_download_path') . $fileName);
$json['token'] = substr($pathinfo['basename'], 0, strrpos($pathinfo['basename'], '.'));
if ($im->writeImages(DIR_IMAGE . $this->config->get('msconf_temp_image_path') . $pathinfo['filename'] . '.png', false)) {
$list = glob(DIR_IMAGE . $this->config->get('msconf_temp_image_path') . $pathinfo['filename'] . '*\\.png');
foreach ($list as $pagePreview) {
$pathinfo = pathinfo($pagePreview);
$this->session->data['multiseller']['files'][] = $pathinfo['basename'];
$thumb = $this->resizeImage($this->config->get('msconf_temp_image_path') . $pathinfo['basename'], $this->config->get('msconf_image_preview_width'), $this->config->get('msconf_image_preview_height'));
$json['images'][] = array('name' => $pathinfo['basename'], 'thumb' => $thumb);
}
//var_dump($this->session->data['multiseller']['files']);
return $json;
}
}
}
示例3: resize_imagick
private function resize_imagick($src, $width, $height, $quality, $preserveExif)
{
try {
$img = new imagick($src);
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality($quality);
if (!$preserveExif) {
try {
$orientation = $img->getImageOrientation();
} catch (ImagickException $e) {
$orientation = 0;
}
$img->stripImage();
if ($orientation) {
$img->setImageOrientation($orientation);
}
}
}
$img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, true);
$result = $img->writeImage($src);
$img->clear();
$img->destroy();
return $result ? true : false;
} catch (Exception $e) {
return false;
}
}
示例4: fopen
<?php
phpinfo();
exit;
$pdf = './manual.pdf';
$fp_pdf = fopen($pdf, 'rb');
$img = new imagick();
// [0] can be used to set page number
$img->setResolution(300, 300);
$img->readImageFile($fp_pdf);
$img->setImageFormat("jpg");
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality(90);
$img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$data = $img->getImageBlob();
示例5: imagick
function _resizeImagick(&$model, $field, $path, $size, $geometry, $thumbnailPath)
{
$srcFile = $path . $model->data[$model->alias][$field];
$pathInfo = $this->_pathinfo($srcFile);
$thumbnailType = $this->settings[$model->alias][$field]['thumbnailType'];
$isMedia = $this->_isMedia($model, $this->runtime[$model->alias][$field]['type']);
$image = new imagick();
if ($isMedia) {
$image->setResolution(300, 300);
$srcFile = $srcFile . '[0]';
}
$image->readImage($srcFile);
$height = $image->getImageHeight();
$width = $image->getImageWidth();
if (preg_match('/^\\[[\\d]+x[\\d]+\\]$/', $geometry)) {
// resize with banding
list($destW, $destH) = explode('x', substr($geometry, 1, strlen($geometry) - 2));
$image->thumbnailImage($destW, $destH);
} elseif (preg_match('/^[\\d]+x[\\d]+$/', $geometry)) {
// cropped resize (best fit)
list($destW, $destH) = explode('x', $geometry);
$image->cropThumbnailImage($destW, $destH);
} elseif (preg_match('/^[\\d]+w$/', $geometry)) {
// calculate heigh according to aspect ratio
$image->thumbnailImage((int) $geometry - 1, 0);
} elseif (preg_match('/^[\\d]+h$/', $geometry)) {
// calculate width according to aspect ratio
$image->thumbnailImage(0, (int) $geometry - 1);
} elseif (preg_match('/^[\\d]+l$/', $geometry)) {
// calculate shortest side according to aspect ratio
$destW = 0;
$destH = 0;
$destW = $width > $height ? (int) $geometry - 1 : 0;
$destH = $width > $height ? 0 : (int) $geometry - 1;
$imagickVersion = phpversion('imagick');
$image->thumbnailImage($destW, $destH, !($imagickVersion[0] == 3));
}
if ($isMedia) {
$thumbnailType = $this->settings[$model->alias][$field]['mediaThumbnailType'];
}
if (!$thumbnailType || !is_string($thumbnailType)) {
try {
$thumbnailType = $image->getImageFormat();
} catch (Exception $e) {
$thumbnailType = 'png';
}
}
$fileName = str_replace(array('{size}', '{filename}'), array($size, $pathInfo['filename']), $this->settings[$model->alias][$field]['thumbnailName']);
$destFile = "{$thumbnailPath}{$fileName}.{$thumbnailType}";
$image->setImageCompressionQuality($this->settings[$model->alias][$field]['thumbnailQuality']);
$image->setImageFormat($thumbnailType);
if (!$image->writeImage($destFile)) {
return false;
}
$image->clear();
$image->destroy();
return true;
}
示例6: _resizeImagick
public function _resizeImagick(Model $model, $field, $path, $size, $geometry, $thumbnailPath)
{
$srcFile = $path . $model->data[$model->alias][$field];
$pathInfo = $this->_pathinfo($srcFile);
$thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['thumbnailType'];
$isMedia = $this->_isMedia($model, $this->runtime[$model->alias][$field]['type']);
$image = new imagick();
if ($isMedia) {
$image->setResolution(300, 300);
$srcFile = $srcFile . '[0]';
}
$image->readImage($srcFile);
$height = $image->getImageHeight();
$width = $image->getImageWidth();
if (preg_match('/^\\[[\\d]+x[\\d]+\\]$/', $geometry)) {
// resize with banding
list($destW, $destH) = explode('x', substr($geometry, 1, strlen($geometry) - 2));
$image->thumbnailImage($destW, $destH, true);
$imageGeometry = $image->getImageGeometry();
$x = ($imageGeometry['width'] - $destW) / 2;
$y = ($imageGeometry['height'] - $destH) / 2;
$image->setGravity(Imagick::GRAVITY_CENTER);
$image->extentImage($destW, $destH, $x, $y);
} elseif (preg_match('/^[\\d]+x[\\d]+$/', $geometry)) {
// cropped resize (best fit)
list($destW, $destH) = explode('x', $geometry);
$image->cropThumbnailImage($destW, $destH);
} elseif (preg_match('/^[\\d]+w$/', $geometry)) {
// calculate heigh according to aspect ratio
$image->thumbnailImage((int) $geometry - 1, 0);
} elseif (preg_match('/^[\\d]+h$/', $geometry)) {
// calculate width according to aspect ratio
$image->thumbnailImage(0, (int) $geometry - 1);
} elseif (preg_match('/^[\\d]+l$/', $geometry)) {
// calculate shortest side according to aspect ratio
$destW = 0;
$destH = 0;
$destW = $width > $height ? (int) $geometry - 1 : 0;
$destH = $width > $height ? 0 : (int) $geometry - 1;
$imagickVersion = phpversion('imagick');
$image->thumbnailImage($destW, $destH, !($imagickVersion[0] == 3));
}
if ($isMedia) {
$thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['mediaThumbnailType'];
}
if (!$thumbnailType || !is_string($thumbnailType)) {
try {
$thumbnailType = $imageFormat = $image->getImageFormat();
// Fix file casing
while (true) {
$ext = false;
$pieces = explode('.', $srcFile);
if (count($pieces) > 1) {
$ext = end($pieces);
}
if (!$ext || !strlen($ext)) {
break;
}
$low = array('ext' => strtolower($ext), 'thumbnailType' => strtolower($thumbnailType));
if ($low['ext'] == 'jpg' && $low['thumbnailType'] == 'jpeg') {
$thumbnailType = $ext;
break;
}
if ($low['ext'] == $low['thumbnailType']) {
$thumbnailType = $ext;
}
break;
}
} catch (Exception $e) {
$this->log($e->getMessage(), 'upload');
$thumbnailType = $imageFormat = 'png';
}
}
$fileName = str_replace(array('{size}', '{filename}', '{primaryKey}'), array($size, $pathInfo['filename'], $model->id), $this->settings[$model->alias][$field]['thumbnailName']);
$destFile = "{$thumbnailPath}{$fileName}.{$thumbnailType}";
$image->setImageCompressionQuality($this->settings[$model->alias][$field]['thumbnailQuality']);
$image->setImageFormat($imageFormat);
if (!$image->writeImage($destFile)) {
return false;
}
$image->clear();
$image->destroy();
return true;
}
示例7: resizeCropImg
private function resizeCropImg($pFolder, $pImg, $pW, $pH)
{
$im = new imagick();
$im->readImage($pFolder . $pImg);
$image = new stdClass();
$image->dimensions = $im->getImageGeometry();
$image->w = $image->dimensions['width'];
$image->h = $image->dimensions['height'];
$image->ratio = $image->w / $image->h;
if ($image->w / $pW < $image->h / $pH) {
$h = ceil($pH * $image->w / $pW);
$y = ($image->h - $pH * $image->w / $pW) / 2;
$im->cropImage($image->w, $h, 0, $y);
} else {
$w = ceil($pW * $image->h / $pH);
$x = ($image->w - $pW * $image->h / $pH) / 2;
$im->cropImage($w, $image->h, $x, 0);
}
$im->ThumbnailImage($pW, $pH, true);
if ($img->type === "PNG") {
$im->setImageCompressionQuality(55);
$im->setImageFormat('png');
} elseif ($img->type === "JPG" || $img->type === "JPEG") {
$im->setCompressionQuality(100);
$im->setImageFormat("jpg");
}
$im->writeImage($this->ad->url->folder . '/assets/' . $pImg);
$im->destroy();
}
示例8: getPdfFromImages
/**
* Generate pdf, preview pdf from images uploaded by user.
*
* @param array $images
*
* @return array
*
* @author Kuldeep Dangi <kuldeep.dangi@yiifrmae.com>
*/
public function getPdfFromImages($images)
{
$fileUploadAbsolutePath = Yii::app()->params['FILE_SERVER_IMAGE_PATH'] . self::FILE_UPLOAD_PATH;
$pdfUploadAbsolutePath = Yii::app()->params['FILE_SERVER_IMAGE_PATH'] . self::FILE_CONVERT_PATH;
$upload_file = array();
$html = $previewHtml = '';
$randomNumber = MD5($this->getRandomNumber());
$savedFileNames = array('image' => $randomNumber . '.jpg', 'imagepdf' => $randomNumber . '.pdf.pdf', 'pdf' => $randomNumber . '.pdf');
$imagesCount = count($images);
$imageCounterCount = 1;
foreach ($images as $image) {
if ($imagesCount > 3 && $imageCounterCount < 4) {
$previewHtml .= '<img src="../' . self::FILE_UPLOAD_PATH . $image . '"/>';
} elseif ($imagesCount < 4 && $imageCounterCount == $imagesCount) {
$previewHtml .= '<img src="../' . self::FILE_UPLOAD_PATH . $image . '"/>';
}
$html .= '<img src="../' . self::FILE_UPLOAD_PATH . $image . '"/>';
$imageCounterCount++;
}
$mpdf = Yii::app()->ePdf->mpdf();
$mpdf->debug = true;
$mpdf->WriteHTML($html);
$mpdf->Output('../' . self::FILE_CONVERT_PATH . $savedFileNames['pdf'], 'F');
$mpdf1 = Yii::app()->ePdf->mpdf();
$mpdf1->debug = true;
$mpdf1->WriteHTML($previewHtml);
$mpdf1->Output('../' . self::FILE_PDF_PREVIEW_PATH . $savedFileNames['imagepdf'], 'F');
$im = new imagick();
$im->readimage('/home/notesgen/public_html/' . self::FILE_PDF_PREVIEW_PATH . $savedFileNames['imagepdf']);
$im->setImageCompressionQuality(0);
$im->setImageFormat('jpeg');
$im->writeImage('../' . self::FILE_IMAGE_PATH . $savedFileNames['image']);
$im->setImageCompressionQuality(80);
$im->writeImage('../' . self::FILE_IMAGE_PATH_APP . $savedFileNames['image']);
$im->clear();
$im->destroy();
return $savedFileNames;
}
示例9: uploadfile
public function uploadfile()
{
$folder = isset($_GET['folder']) ? $_GET['folder'] : 'others';
$targetFolder = "/upload_file/{$folder}";
$prefix = time();
$setting = $this->general_model->get_email_from_setting();
$type = explode(",", $setting[0]['download_type']);
foreach ($type as $key => $value) {
$type[$key] = strtolower($value);
}
$userid = $_SESSION['user']['user_id'];
if (!empty($_FILES)) {
$_FILES["Filedata"]["name"] = str_replace(' ', '', $_FILES["Filedata"]["name"]);
$_FILES["Filedata"]["tmp_name"] = str_replace(' ', '', $_FILES["Filedata"]["tmp_name"]);
$uploaddatafile1 = md5($_FILES["Filedata"]["name"]);
$tempFile = $_FILES["Filedata"]["tmp_name"];
$targetPath = $_SERVER["DOCUMENT_ROOT"] . $targetFolder;
$targetFile = rtrim($targetPath, "/") . "/" . $_FILES["Filedata"]["name"];
$fileTypes = $type;
//array("zip","rar");
$fileParts = pathinfo($_FILES["Filedata"]["name"]);
if (in_array(strtolower($fileParts["extension"]), $fileTypes)) {
move_uploaded_file($tempFile, $targetFile);
if (isset($_GET['w'])) {
$w = $_GET['w'];
} else {
$w = 100;
}
if (isset($_GET['h'])) {
$h = $_GET['h'];
} else {
$h = 100;
}
$path_upload = "upload_file/{$folder}/" . $_FILES["Filedata"]["name"];
$root = dirname(dirname(dirname(__FILE__)));
$file = '/' . $path_upload;
//a reference to the file in reference to the current working directory.
// Process for image
$image_info = @getimagesize(base_url() . $path_upload);
if (!empty($image_info)) {
$image = true;
} else {
$image = false;
}
if ($image) {
if (!isset($_SESSION['fileuploadname'])) {
$_SESSION['fileuploadname'] = $_FILES["Filedata"]["name"];
$_SESSION['fileuploadhtml'] = '';
} else {
if (empty($_SESSION['fileuploadname'])) {
$_SESSION['fileuploadname'] = $_FILES["Filedata"]["name"];
$_SESSION['fileuploadhtml'] = '';
}
}
$_SESSION['fileuploadhtml'] .= '<img src="' . base_url() . $path_upload . '" style="width:850px;"/>';
echo "2";
exit;
}
include $root . "/mpdf/mpdf.php";
require_once $root . "/scribd.php";
$scribd_api_key = "766ydp7ellofhr7x027wl";
$scribd_secret = "sec-7zrz2fxxa2chak965tbp67npqw";
$scribd = new Scribd($scribd_api_key, $scribd_secret);
$doc_type = null;
$access = "private";
$rev_id = null;
$data = $scribd->upload($file, $doc_type, $access, $rev_id);
if (!empty($data)) {
$result = 0;
while ($result == 0) {
echo $result = $scribd->getDownloadLinks($data['doc_id']);
}
file_put_contents('/upload_file/files/c' . $uploaddatafile1 . ".pdf", fopen($result["download_link"], 'r'));
//file_put_contents( fopen($result["download_link"], 'r'));
$mpdf = new mPDF();
$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile('/upload_file/files/r' . $uploaddatafile1 . ".pdf");
$tplId = $mpdf->ImportPage(1);
$mpdf->UseTemplate($tplId);
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetWatermarkText(' ');
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->showWatermarkText = true;
$md5 = $uploaddatafile1;
$mpdf->Output('/upload_file/files/' . $md5 . '.pdf', '');
$mpdf->Thumbnail('/upload_file/files/' . $md5 . '.pdf', 1);
$mpdf->Output('/upload_file/files/' . $md5 . '.pdf', '');
unlink('/upload_file/files/c' . $uploaddatafile1 . ".pdf");
$im = new imagick();
$im->readimage('/upload_file/files/' . $md5 . '.pdf');
//$im->readimage('/upload_file/files/'.$md5.'.pdf');
$im->setImageCompressionQuality(0);
$im->setImageFormat('jpeg');
$im->writeImage('/upload_file/images/r' . $md5 . '.jpg');
$this->db->set('id', $userid);
$this->db->set('fullpdf', '/upload_file/files/r' . $uploaddatafile1 . '.pdf');
$this->db->set('pdf', '/upload_file/files/' . $md5 . '.pdf');
$this->db->set('image', '/upload_file/images/r' . $md5 . '.jpg');
$this->db->insert('scribe');
$im->clear();
//.........这里部分代码省略.........
示例10: resize
public static function resize($orig_file_path, $settings, $target_file_path)
{
$quality = 95;
$crop = $settings['crop_method'];
$current_width = $settings['width'];
$current_height = $settings['height'];
$target_width = min($current_width, $settings['width_requested']);
$target_height = min($current_height, $settings['height_requested']);
if ($crop) {
$x_ratio = $target_width / $current_width;
$y_ratio = $target_height / $current_height;
$ratio = min($x_ratio, $y_ratio);
$use_x_ratio = $x_ratio == $ratio;
$new_width = $use_x_ratio ? $target_width : floor($current_width * $ratio);
$new_height = !$use_x_ratio ? $target_height : floor($current_height * $ratio);
} else {
$new_width = $target_width;
$new_height = $target_height;
}
$im = new imagick($orig_file_path);
$im->cropThumbnailImage($new_width, $new_height);
$im->setImageCompression(imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality($quality);
$im->stripImage();
$result = $im->writeImage($target_file_path);
$im->destroy();
return array($new_width, $new_height, $target_width, $target_height);
}