当前位置: 首页>>代码示例>>PHP>>正文


PHP imagick类代码示例

本文整理汇总了PHP中imagick的典型用法代码示例。如果您正苦于以下问题:PHP imagick类的具体用法?PHP imagick怎么用?PHP imagick使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了imagick类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cdm_thumbPdf

 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;
     }
 }
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:33,代码来源:functions.php

示例2: 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();
 }
开发者ID:kuldeepro,项目名称:notesgen,代码行数:29,代码来源:CronController.php

示例3: 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;
}
开发者ID:arfanty,项目名称:acp,代码行数:28,代码来源:testValidate.php

示例4: 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;
 }
开发者ID:loulancn,项目名称:core,代码行数:38,代码来源:office.php

示例5: makethumb

function makethumb($srcFile, $dstFile, $dstW, $dstH, $imwf = false)
{
    $im = new imagick($srcFile);
    $source_w = $im->getImageWidth();
    $source_h = $im->getImageHeight();
    if ($dstW === 0 && $dstH === 0) {
        $dstW = $source_w;
        $dstH = $source_h;
    } else {
        // 取得縮在此範圍內的比例
        $percent = getResizePercent($source_w, $source_h, $dstW, $dstH);
        $dstW = $source_w * $percent;
        $dstH = $source_h * $percent;
    }
    $im->thumbnailImage($dstW, $dstH);
    $im->writeImage($dstFile);
    $watermarkFile = './logo.png';
    if ($imwf && is_file($watermarkFile) && is_file($dstFile)) {
        $image = new imagick($dstFile);
        $watermark = new imagick($watermarkFile);
        $iWidth = $image->getImageWidth();
        $iHeight = $image->getImageHeight();
        $wWidth = $watermark->getImageWidth();
        $wHeight = $watermark->getImageHeight();
        if ($iHeight < $wHeight || $iWidth < $wWidth) {
            $watermark->scaleImage($iWidth, $iHeight);
            $wWidth = $watermark->getImageWidth();
            $wHeight = $watermark->getImageHeight();
        }
        $x = ($iWidth - $wWidth) / 2;
        $y = ($iHeight - $wHeight) / 2;
        $image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
        $image->writeImage($dstFile);
    }
}
开发者ID:FantasticThought,项目名称:tfsda,代码行数:35,代码来源:image_conver.php

示例6: 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;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:29,代码来源:office-cl.php

示例7: 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;
 }
开发者ID:agus-ariyanto,项目名称:koio,代码行数:9,代码来源:pdf.php

示例8: 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);
}
开发者ID:bramleksono,项目名称:mobileid-SI,代码行数:10,代码来源:pdfoperation.php

示例9: createThumb

 private function createThumb($filePath, $fileName)
 {
     if (!extension_loaded('imagick')) {
         $errorMessage = "Error: 874";
         $this->error($errorMessage);
     }
     try {
         $fileNameWithoutExt = $fileName;
         $imagePreview = new imagick($this->uploadsDir . $fileName);
         $imagePreview->scaleImage(300, 0);
         $imagePreview->writeImage($this->thumbDir . $fileNameWithoutExt);
     } catch (ImagickException $e) {
         $errorMessage = "Error: 3435";
         $this->error($errorMessage);
     }
     return $fileNameWithoutExt;
 }
开发者ID:mawilliamson,项目名称:wordpress,代码行数:17,代码来源:file_uploader.php

示例10: 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;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:17,代码来源:pdf.php

示例11: 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;
 }
开发者ID:xavit,项目名称:OffenesBonn,代码行数:64,代码来源:makefile.php

示例12: 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;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:20,代码来源:office-fallback.php

示例13: generate

 private function generate()
 {
     $taken_seats_result = $this->seatbooking->get_taken_seats_ids();
     $taken_seats = array();
     foreach ($taken_seats_result as $seat) {
         $taken_seats[$seat] = 0;
     }
     $coords = $this->load_xmlconfig_to_array();
     $taken_seats_coords = array_intersect_key($coords, $taken_seats);
     $bg = new imagick($this->filename_bg);
     $marker = new imagick($this->filename_marker);
     $marker_width = $marker->getImageWidth();
     $marker_height = $marker->getImageHeight();
     foreach ($taken_seats_coords as $seat) {
         $x = $seat[0] - floor($marker_width / 2);
         $y = $seat[1] - floor($marker_width / 2);
         $bg->compositeImage($marker, imagick::COMPOSITE_OVER, $x, $y);
     }
     return $bg;
 }
开发者ID:bjornua,项目名称:dikulan-old,代码行数:20,代码来源:StatusImage.php

示例14: pigen_generate

function pigen_generate($file)
{
    // Generate thumbnail from PDF
    $file_basename = str_replace('.', '-', basename($file));
    $file_url = str_replace(basename($file), $file_basename . '.jpg', $file);
    $opt = get_option('_pigen_verify_imagick');
    if ($opt == 'imagick') {
        $im = new imagick();
        $im->readimage($file . '[0]');
        $im->setImageBackgroundColor('white');
        $im = $im->flattenImages();
        $im->setImageFormat('jpg');
        $im->writeImage($file_url);
        $im->clear();
        $im->destroy();
    } else {
        exec("convert {$file}[0] -density 72 -quality 90 -background white -flatten {$file_url}");
        // converte files to jpg
    }
    return $file_url;
}
开发者ID:subhadip-sahoo,项目名称:wp-project1,代码行数:21,代码来源:pdf-image-generator.php

示例15: 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();
}
开发者ID:beemoon,项目名称:signage,代码行数:30,代码来源:function.php


注:本文中的imagick类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。