本文整理汇总了PHP中imagick::setImageFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::setImageFormat方法的具体用法?PHP imagick::setImageFormat怎么用?PHP imagick::setImageFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagick
的用法示例。
在下文中一共展示了imagick::setImageFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mkdir
function cdm_thumbPdf($pdf)
{
if (class_exists('imagick')) {
$upload_dir = wp_upload_dir();
$tmp_folder = $upload_dir['basedir'] . '/imageMagick_tmp/';
if (!is_dir($tmp_folder)) {
mkdir($tmp_folder, 0777);
}
$tmp = $tmp_folder;
$format = "png";
$source = $pdf;
$dest = "" . $pdf . "_big.{$format}";
$dest2 = "" . $pdf . "_small.{$format}";
// read page 1
$im = new imagick('' . $source . '[0]');
// convert to jpg
$im->setImageColorspace(255);
$im->setImageFormat($format);
//resize
$im->resizeImage(650, 650, imagick::FILTER_LANCZOS, 1);
//write image on server
$im->writeImage($dest);
//resize
$im->resizeImage(250, 250, imagick::FILTER_LANCZOS, 1);
//write image on server
$im->writeImage($dest2);
$im->clear();
$im->destroy();
} else {
echo 'php-image-magick not installed. Please disable the pdf thumbnail options or install the php extention correctly.';
exit;
}
}
示例2: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$this->initCmd();
if (is_null($this->cmd)) {
return false;
}
$absPath = $fileview->toTmpFile($path);
$tmpDir = get_temp_dir();
$defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
$clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
$export = 'export HOME=/' . $tmpDir;
shell_exec($export . "\n" . $exec);
//create imagick object from pdf
try {
$pdf = new \imagick($absPath . '.pdf' . '[0]');
$pdf->setImageFormat('jpg');
} catch (\Exception $e) {
unlink($absPath);
unlink($absPath . '.pdf');
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
$image = new \OC_Image();
$image->loadFromData($pdf);
unlink($absPath);
unlink($absPath . '.pdf');
return $image->valid() ? $image : false;
}
示例3: 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();
}
示例4: 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();
}
示例5: getThumbnail
/**
* {@inheritDoc}
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$this->initCmd();
if (is_null($this->cmd)) {
return false;
}
$absPath = $fileview->toTmpFile($path);
$tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
$clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
shell_exec($exec);
//create imagick object from pdf
$pdfPreview = null;
try {
list($dirname, , , $filename) = array_values(pathinfo($absPath));
$pdfPreview = $dirname . '/' . $filename . '.pdf';
$pdf = new \imagick($pdfPreview . '[0]');
$pdf->setImageFormat('jpg');
} catch (\Exception $e) {
unlink($absPath);
unlink($pdfPreview);
\OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
return false;
}
$image = new \OC_Image();
$image->loadFromData($pdf);
unlink($absPath);
unlink($pdfPreview);
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
return false;
}
示例6: thumbnail
function thumbnail($file, $width = '120')
{
$name = $this->_dir . DS . $file . '[0]';
$im = new imagick($name);
$im->setImageFormat('jpg');
$im->scaleImage($width, 0);
header('Content-Type: image/jpeg');
echo $im;
}
示例7: pdftoimage
function pdftoimage($file, $page)
{
$filepart = pathinfo($file);
$save_to = $filepart['filename'] . ".jpg";
$im = new imagick($file[$page - 1]);
$im->thumbnailImage(800, 0);
$im->setImageFormat('jpg');
$im = $im->flattenImages();
file_put_contents($save_to, $im);
}
示例8: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$tmpPath = $fileview->toTmpFile($path);
//create imagick object from pdf
try {
$pdf = new \imagick($tmpPath . '[0]');
$pdf->setImageFormat('jpg');
} catch (\Exception $e) {
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
unlink($tmpPath);
//new image object
$image = new \OC_Image($pdf);
//check if image object is valid
return $image->valid() ? $image : false;
}
示例9: getThumbnail
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
require_once 'PHPExcel/Classes/PHPExcel.php';
require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
$absPath = $fileview->toTmpFile($path);
$tmpPath = \OC_Helper::tmpFile();
$rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf';
\PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$phpexcel = new \PHPExcel($absPath);
$excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
$excel->save($tmpPath);
$pdf = new \imagick($tmpPath . '[0]');
$pdf->setImageFormat('jpg');
unlink($absPath);
unlink($tmpPath);
$image = new \OC_Image();
$image->loadFromData($pdf);
return $image->valid() ? $image : false;
}
示例10: 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;
}
示例11: 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;
}
}
}
示例12: imagick
<?php
define("JPEG_FILE", __DIR__ . "/imagick_test.jpg");
define("PNG_FILE", __DIR__ . "/imagick_test.png");
$im = new imagick('magick:rose');
$im->writeImage(JPEG_FILE);
$im->clear();
// This is the problematic case, setImageFormat doesn't really
// affect writeImageFile.
// So in this case we want to write PNG but file should come out
// as JPEG
$fp = fopen(PNG_FILE, "w+");
$im->readImage(JPEG_FILE);
$im->setImageFormat('png');
$im->writeImageFile($fp);
$im->clear();
fclose($fp);
// Output the format
$identify = new Imagick(PNG_FILE);
echo $identify->getImageFormat() . PHP_EOL;
// Lets try again, setting the filename rather than format
// This should cause PNG image to be written
$fp = fopen(PNG_FILE, "w+");
$im->readImage(JPEG_FILE);
$im->setImageFilename('png:');
$im->writeImageFile($fp);
$im->clear();
fclose($fp);
// If all goes according to plan, on second time we should get PNG
$identify = new Imagick(PNG_FILE);
echo $identify->getImageFormat() . PHP_EOL;
示例13: system
} else {
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
示例14: 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();
示例15: createTmb
/**
* Create thumnbnail and return it's URL on success
*
* @param string $path file path
* @param $stat
* @return false|string
* @internal param string $mime file mime type
* @author Dmitry (dio) Levashov
*/
protected function createTmb($path, $stat)
{
if (!$stat || !$this->canCreateTmb($path, $stat)) {
return false;
}
$name = $this->tmbname($stat);
$tmb = $this->tmbPath . DIRECTORY_SEPARATOR . $name;
// copy image into tmbPath so some drivers does not store files on local fs
if (($src = $this->fopenCE($path, 'rb')) == false) {
return false;
}
if (($trg = fopen($tmb, 'wb')) == false) {
$this->fcloseCE($src, $path);
return false;
}
while (!feof($src)) {
fwrite($trg, fread($src, 8192));
}
$this->fcloseCE($src, $path);
fclose($trg);
$result = false;
$tmbSize = $this->tmbSize;
if ($this->imgLib === 'imagick') {
try {
$imagickTest = new imagick($tmb);
$imagickTest->clear();
$imagickTest = true;
} catch (Exception $e) {
$imagickTest = false;
}
}
if ($this->imgLib === 'imagick' && !$imagickTest || ($s = @getimagesize($tmb)) === false) {
if ($this->imgLib === 'imagick') {
try {
$imagick = new imagick();
$imagick->setBackgroundColor(new ImagickPixel($this->options['tmbBgColor']));
$imagick->readImage($this->getExtentionByMime($stat['mime'], ':') . $tmb);
$imagick->setImageFormat('png');
$imagick->writeImage($tmb);
$imagick->clear();
if (($s = @getimagesize($tmb)) !== false) {
$result = true;
}
} catch (Exception $e) {
}
}
if (!$result) {
unlink($tmb);
return false;
}
$result = false;
}
/* If image smaller or equal thumbnail size - just fitting to thumbnail square */
if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) {
$result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
} else {
if ($this->options['tmbCrop']) {
$result = $tmb;
/* Resize and crop if image bigger than thumbnail */
if (!($s[0] > $tmbSize && $s[1] <= $tmbSize || $s[0] <= $tmbSize && $s[1] > $tmbSize) || $s[0] > $tmbSize && $s[1] > $tmbSize) {
$result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
}
if ($result && ($s = @getimagesize($tmb)) != false) {
$x = $s[0] > $tmbSize ? intval(($s[0] - $tmbSize) / 2) : 0;
$y = $s[1] > $tmbSize ? intval(($s[1] - $tmbSize) / 2) : 0;
$result = $this->imgCrop($result, $tmbSize, $tmbSize, $x, $y, 'png');
} else {
$result = false;
}
} else {
$result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, true, 'png');
}
if ($result) {
$result = $this->imgSquareFit($result, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
}
}
if (!$result) {
unlink($tmb);
return false;
}
return $name;
}