本文整理汇总了PHP中imagick::setCompressionQuality方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::setCompressionQuality方法的具体用法?PHP imagick::setCompressionQuality怎么用?PHP imagick::setCompressionQuality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagick
的用法示例。
在下文中一共展示了imagick::setCompressionQuality方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pdf2png
function pdf2png($PDF,$Path){
if(!extension_loaded('imagick')){
echo 'no imagick';
return false;
}
if(!file_exists($PDF)){
echo 'no file';
return false;
}
$IM = new imagick();
echo 'image create';
// $IM->setResolution(794,1123);
// echo 'image resolution';
$IM->setCompressionQuality(100);
echo 'image quality';
$IM->readImage($PDF);
echo 'pdf read';
foreach ($IM as $Key => $Var){
echo 'image convert';
$Var->setImageFormat('png');
$Filename = $Path.'/'.md5($Key.time()).'.png';
if($Var->writeImage($Filename) == true){
$Return[] = $Filename;
}
}
return $Return;
}
示例2: pdftojpg
function pdftojpg($pdfFile, $jpgFile)
{
/*
* imagemagick and php5-imagick required
*
* all options for imagick:
* http://php.net/manual/fr/class.imagick.php
*
*/
$pdf_file = $pdfFile;
$save_to = $jpgFile;
$img = new imagick();
//this must be called before reading the image, otherwise has no effect - "-density {$x_resolution}x{$y_resolution}"
//this is important to give good quality output, otherwise text might be unclear
$img->setResolution(200, 200);
//read the pdf
$img->readImage("{$pdf_file}[0]");
//reduce the dimensions - scaling will lead to black color in transparent regions
$img->scaleImage(1920, 1080);
//set new format
$img->setCompressionQuality(80);
$img->setImageFormat('jpg');
// -flatten option, this is necessary for images with transparency, it will produce white background for transparent regions
$img = $img->flattenImages();
//save image file
$img->writeImages($save_to, false);
//clean
$img->clear();
$img->destroy();
}
示例3: generatePreviewImage
public function generatePreviewImage($pdfFile, $saveTo)
{
try {
$img = new imagick(Director::getAbsFile($pdfFile) . "[0]");
//we only take first page
// -flatten option, this is necessary for images with transparency, it will produce white background for transparent regions
$img->setImageAlphaChannel(11);
//Imagick::ALPHACHANNEL_REMOVE has been added in 3.2.0b2
$img->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);
//set new format
//@Todo detect format from filename
$img->setImageFormat('jpg');
$img->setCompressionQuality(100);
//save image file
$img->writeImages($saveTo, false);
} catch (\Exception $e) {
error_log($e->getMessage());
return false;
}
return true;
}
示例4: pdf2png
function pdf2png($PDF,$Path,$ImageName){
if(!extension_loaded('imagick')){
echo "<p>no imagick'</p>";
return false;
}
if(!file_exists($PDF)){
echo "<p>no file'</p>";
return false;
}
$IM = new imagick();
$IM->setOption('density','200');
$IM->setOption('antialias','');
$IM->setOption('sharpen','0x1.0');
//$IM->setResolution(794,1123);
// echo 'image resolution';
$IM->setCompressionQuality(100);
$IM->readImage($PDF);
foreach ($IM as $Key => $Var){
$Var->paintTransparentImage($Var->getImageBackgroundColor(), 1, 10000);
$Var->setImageFormat('png');
$Filename = $Path.'/'.$ImageName.'.png';
if($Var->writeImage($Filename) == true){
$Return[] = $Filename;
}
}
return $Return;
}
示例5: resize_imagick
private function resize_imagick($src, $width, $height, $quality)
{
try {
$img = new imagick($src);
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setCompressionQuality($quality);
}
$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;
}
}
示例6: 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();
}
示例7: system
if (PHP_OS == 'Linux') {
//Linux平台
$wbshell1 = "xvfb-run --server-args=\"-screen 0, 1024x768x24\" cutycapt --min-width=460 --url=" . $site_url . " --out=" . $img_name;
$wbshell2 = "xvfb-run --server-args=\"-screen 0, 1024x768x24\" cutycapt --min-width=1024 --url=" . $site_url . " --out=" . $img_name;
}
}
//根据生成图片的大小调用语句
$wbshell = $picsize == 1 ? $wbshell1 : $wbshell2;
//执行截图语句
system($wbshell);
//exec($wbshell);
//注:下面的操作仅是对图片进一步进行调整,可以缩小图片体积等,并方便更多的处理,并非必须。
$im = new imagick($img_name);
//if($picsize==1) $im->resizeImage(490,0,Imagick::FILTER_LANCZOS,1);
$im->setImageFormat("png");
$im->setCompressionQuality(90);
$img_name2 = 'html2png/' . time() . '.png';
$im->writeImage($img_name2);
$im->clear();
$im->destroy();
//输出图片连接
$url_this = dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]) . '/' . $img_name2;
} else {
$url_this = dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]) . '/google.png';
}
?>
<div class="wrapper" >
<h1>内容生成工具</h1>
<ul>
<li><?php
echo $errinfo;
示例8: create_img_frompdf
/**
* class_make_file::create_img_frompdf()
*
* @param mixed $pdf_org
* @param mixed $pfadhier
* @return
*/
private function create_img_frompdf($pdf_org, $pfadhier)
{
setlocale(LC_ALL, "de_DE");
//Klasse INI
$im = new imagick();
//Auflösung
$im->setResolution(60, 60);
//Anzahl der Seiten des PDFs
$pages = $this->getNumPagesInPDF($pfadhier . $pdf_org);
//Dann alle Seiten durchlaufen und Bilder erzeugen
for ($i = 0; $i < $pages; $i++) {
//Maximal 100 Seiten
if ($i > 100) {
continue;
}
//Seitenzahl festlegen
$pdf = $pfadhier . $pdf_org . "[" . $i . "]";
//auslesen
if (file_exists($pfadhier . $pdf_org)) {
try {
$im->readImage($pdf);
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
}
if (empty($e)) {
//die ("NIX");
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(60);
$im->setImageFormat('jpg');
$im->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
//Damti testweise ausgeben
#header( "Content-Type: image/png" );
#echo $im;
#exit();
$pdf_img = str_replace(".pdf", "", $pdf_org);
$pdf_img = str_replace("/files/pdf/", "", $pdf_img);
$im->setImageFileName($pfadhier . "files/images/thumbs/" . $pdf_img . "_" . $i . ".jpg");
//Pfade saven
echo $image_files[] = $pfadhier . "files/images/thumbs/" . $pdf_img . "_" . $i . ".jpg";
//Speichern
$im->writeImage();
ini_set(Display_errors, "1");
}
//Noch verkleinern... image_magick macht die Bilder zu groß
/**
$image = new SimpleImage();
$image->load($pfadhier."files/images/thumbs/".$pdf_img."_".$i.".jpg");
$image->resizeToHeight(300);
$image->save($pfadhier."files/images/thumbs/".$pdf_img."_".$i."x.jpg");
unlink($pfadhier."files/images/thumbs/".$pdf_img."_".$i.".jpg");
echo ($pfadhier."files/images/thumbs/".$pdf_img."_".$i."x.jpg");
*/
}
}
return $image_files;
}