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


PHP imagick::writeImages方法代码示例

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


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

示例1: date

     // узнаем размеры оригинального изображения
     $im_width = $im->getImageWidth();
     $im_height = $im->getImageHeight();
     // узнаем размеры водяного знака
     $watermark_width = $watermark->getImageWidth();
     $watermark_height = $watermark->getImageHeight();
     // посчитать x и y
     $left = $im_width - $watermark_width - 10;
     $top = $im_height - $watermark_height - 10;
     // накладываем watermark на оригинальное изображение
     $im->compositeImage($watermark, imagick::COMPOSITE_OVER, $left, $top);
     // сохраняем оригинал
     $im->writeImage('./images/' . $image_name . '.' . $p[1]);
 } else {
     // сохраняем .gif с учетом анимации
     $im->writeImages('./images/' . $image_name . '.' . $p[1], true);
 }
 // Копируем объект для различных типов
 $large = $im->clone();
 $square = $im->clone();
 // Создаем квадратное изображение 160x160 px
 $square->cropThumbnailImage(160, 160);
 $square->writeImage('./images/' . $image_name . 's' . '.' . $p[1]);
 // Создаем большое изображение с шириной 640 px и переменной высотой
 $large->thumbnailImage(640, 0);
 $large->writeImage('./images/' . $image_name . 'l' . '.' . $p[1]);
 // добавляем имя, расширение, дату загрузки изображения в БД
 // выбираем коллекцию
 $collection = $db->images;
 // добавляем новый документ - изображение в коллекцию Images
 $collection->insert(array('image' => $image_name, 'ext' => $p[1], 'title' => '', 'views' => 0, 'gallery' => 0, 'date' => date("d-m-Y H:i:s")));
开发者ID:iSkript,项目名称:Imgur-clone,代码行数:31,代码来源:upload.php

示例2: 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;
 }
开发者ID:ivoba,项目名称:silverstripe-simple-pdf-preview,代码行数:21,代码来源:SimplePdfPreviewImagickGenerator.php

示例3: 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;
         }
     }
 }
开发者ID:ngogiangthanh,项目名称:choloncantho-final,代码行数:46,代码来源:msfile.php

示例4: convert

 /**
  * Convert to output format. This method convert from pdf to specified format with optimizing
  * @throw Exception
  * @access public
  * @param string $outputPath - path to file. May content only path or path with filename
  * @param int/string[=ALL] $page - number of document page wich will be converted into image. If specified 'ALL' - will be converted all pages.
  * @param string $format - output format (see self::getFormats())
  * @param array $resolution - array with x&y resolution DPI
  * @param int $depth - bit depth image
  * @return string/bool[false] - return image path of last converted page
  */
 public function convert($outputPath = '', $page = 'ALL', $format = 'png', $resolution = array('x' => 300, 'y' => 300), $depth = 8)
 {
     if (!Imagick::queryFormats(strtoupper($format))) {
         throw new Exception('Unsupported format');
     }
     $startTime = microtime(true);
     $im = new imagick();
     $im->setResolution($resolution['x'], $resolution['y']);
     $format = strtolower($format);
     $im->setFormat($format);
     if ($outputPath) {
         if (is_dir($outputPath)) {
             $outputPath = $outputPath . pathinfo($this->filePathWithoutType, PATHINFO_FILENAME);
         }
         $outputFileName = $outputPath;
     } else {
         $outputFileName = $this->filePathWithoutType;
     }
     if ($page === 'ALL') {
         $im->readImage($this->filePathWithoutType . '.pdf');
         $im->setImageFormat($format);
         $im->setImageAlphaChannel(11);
         // it's a new constant imagick::ALPHACHANNEL_REMOVE
         $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
         $im->setOption($format . ':bit-depth', $depth);
         $im->writeImages($outputFileName . "." . $format, false);
         $logString = '[POINT] File "' . $this->filePathWithoutType . '.pdf" converted to "' . $format . '" with ' . $im->getNumberImages() . ' pages (ex: ' . (microtime(true) - $startTime) . 's)';
         $this->setLog($logString);
         //Optimizing
         if ($format == 'png' && $this->optipngChecking()) {
             $startTime = microtime(true);
             for ($page = $i = 0; $i < $im->getNumberImages(); $i++) {
                 $this->execute('optipng -o=5', $outputFileName . "-" . (int) $i . "." . $format);
             }
             $logString = '[POINT] Files "' . $outputFileName . '-x.' . $format . '" optimized (ex: ' . (microtime(true) - $startTime) . 's)';
             $this->setLog($logString);
         }
     } else {
         $im->readImage($this->filePathWithoutType . '.pdf[' . (int) $page . ']');
         $im->setImageFormat($format);
         $im->setImageAlphaChannel(11);
         // it's a new constant imagick::ALPHACHANNEL_REMOVE
         $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
         $im->setOption($format . ':color-type', 2);
         $im->setOption($format . ':bit-depth', $depth);
         $im->writeImage($outputFileName . "-" . (int) $page . "." . $format);
         $logString = '[POINT] File "' . $outputFileName . '.pdf" converted to "' . $format . '" one page (ex: ' . (microtime(true) - $startTime) . 's)';
         $this->setLog($logString);
         //Optimizing
         if ($format == 'png' && $this->optipngChecking()) {
             $startTime = microtime(true);
             $this->execute('optipng -o=5', $outputFileName . "-" . (int) $page . "." . $format);
             $logString = '[POINT] File "' . $outputFileName . "-" . (int) $page . "." . $format . '" optimized (ex: ' . (microtime(true) - $startTime) . 's)';
             $this->setLog($logString);
         }
     }
     if (file_exists($outputFileName . "-" . (int) $page . "." . $format)) {
         return $outputFileName . "-" . (int) $page . "." . $format;
     } else {
         return false;
     }
 }
开发者ID:Kreker,项目名称:doc2image,代码行数:73,代码来源:Doc2Image.php


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