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


PHP imagick::getImageFormat方法代码示例

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


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

示例1: 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;
     }
 }
开发者ID:idea-lab,项目名称:Spectrum,代码行数:28,代码来源:plugin.php

示例2: _prepareFilesForDeletion

 /**
  * Sets up an array of files to be deleted
  *
  * @param Model $model Model instance
  * @param string $field Name of field being modified
  * @param array $data array of data
  * @param array $options array of configuration settings for a field
  * @return boolean
  **/
 protected function _prepareFilesForDeletion(Model $model, $field, $data, $options = array())
 {
     if ($options['keepFilesOnDelete'] === true) {
         return array();
     }
     if (!strlen($data[$model->alias][$field])) {
         return $this->__filesToRemove;
     }
     if (!empty($options['fields']['dir']) && isset($data[$model->alias][$options['fields']['dir']])) {
         $dir = $data[$model->alias][$options['fields']['dir']];
     } else {
         if (in_array($options['pathMethod'], array('_getPathFlat', '_getPathPrimaryKey'))) {
             $model->id = $data[$model->alias][$model->primaryKey];
             $dir = call_user_func(array($this, '_getPath'), $model, $field);
         } else {
             CakeLog::error(sprintf('Cannot get directory to %s.%s: %s pathMethod is not supported.', $model->alias, $field, $options['pathMethod']));
         }
     }
     $filePathDir = $this->settings[$model->alias][$field]['path'] . (empty($dir) ? '' : $dir . DS);
     $filePath = $filePathDir . $data[$model->alias][$field];
     $pathInfo = $this->_pathinfo($filePath);
     if (!isset($this->__filesToRemove[$model->alias])) {
         $this->__filesToRemove[$model->alias] = array();
     }
     $this->__filesToRemove[$model->alias][] = $filePath;
     $this->__foldersToRemove[$model->alias][] = $dir;
     $createThumbnails = $options['thumbnails'];
     $hasThumbnails = !empty($options['thumbnailSizes']);
     if (!$createThumbnails || !$hasThumbnails) {
         return $this->__filesToRemove;
     }
     $directorySeparator = empty($dir) ? '' : DIRECTORY_SEPARATOR;
     $mimeType = $this->_getMimeType($filePath);
     $isMedia = $this->_isMedia($mimeType);
     $isImagickResize = $options['thumbnailMethod'] == 'imagick';
     $thumbnailType = $options['thumbnailType'];
     if ($isImagickResize) {
         if ($isMedia) {
             $thumbnailType = $options['mediaThumbnailType'];
         }
         if (!$thumbnailType || !is_string($thumbnailType)) {
             try {
                 $srcFile = $filePath;
                 $image = new imagick();
                 if ($isMedia) {
                     $image->setResolution(300, 300);
                     $srcFile = $srcFile . '[0]';
                 }
                 $image->readImage($srcFile);
                 $thumbnailType = $image->getImageFormat();
             } catch (Exception $e) {
                 $thumbnailType = 'png';
             }
         }
     } else {
         if (!$thumbnailType || !is_string($thumbnailType)) {
             $thumbnailType = $pathInfo['extension'];
         }
         if (!$thumbnailType) {
             $thumbnailType = 'png';
         }
     }
     foreach ($options['thumbnailSizes'] as $size => $geometry) {
         $fileName = str_replace(array('{size}', '{geometry}', '{filename}', '{primaryKey}', '{time}', '{microtime}'), array($size, $geometry, $pathInfo['filename'], $model->id, time(), microtime()), $options['thumbnailName']);
         $thumbnailPath = $options['thumbnailPath'];
         $thumbnailPath = $this->_pathThumbnail($model, $field, compact('geometry', 'size', 'thumbnailPath'));
         $thumbnailFilePath = "{$thumbnailPath}{$dir}{$directorySeparator}{$fileName}.{$thumbnailType}";
         $this->__filesToRemove[$model->alias][] = $thumbnailFilePath;
     }
     return $this->__filesToRemove;
 }
开发者ID:hotanlam,项目名称:japansource,代码行数:80,代码来源:UploadBehavior.php

示例3: array

 function _prepareFilesForDeletion(&$model, $field, $data, $options)
 {
     if (!strlen($data[$model->alias][$field])) {
         return $this->__filesToRemove;
     }
     $dir = $data[$model->alias][$options['fields']['dir']];
     $filePathDir = $this->settings[$model->alias][$field]['path'] . $dir . DS;
     $filePath = $filePathDir . $data[$model->alias][$field];
     $pathInfo = $this->_pathinfo($filePath);
     $this->__filesToRemove[$model->alias] = array();
     $this->__filesToRemove[$model->alias][] = $filePath;
     $createThumbnails = $options['thumbnails'];
     $hasThumbnails = !empty($options['thumbnailSizes']);
     if (!$createThumbnails || !$hasThumbnails) {
         return $this->__filesToRemove;
     }
     $DS = DIRECTORY_SEPARATOR;
     $mimeType = $this->_getMimeType($filePath);
     $isMedia = $this->_isMedia($model, $mimeType);
     $isImagickResize = $options['thumbnailMethod'] == 'imagick';
     $thumbnailType = $options['thumbnailType'];
     if ($isImagickResize) {
         if ($isMedia) {
             $thumbnailType = $options['mediaThumbnailType'];
         }
         if (!$thumbnailType || !is_string($thumbnailType)) {
             try {
                 $srcFile = $filePath;
                 $image = new imagick();
                 if ($isMedia) {
                     $image->setResolution(300, 300);
                     $srcFile = $srcFile . '[0]';
                 }
                 $image->readImage($srcFile);
                 $thumbnailType = $image->getImageFormat();
             } catch (Exception $e) {
                 $thumbnailType = 'png';
             }
         }
     } else {
         if (!$thumbnailType || !is_string($thumbnailType)) {
             $thumbnailType = $pathInfo['extension'];
         }
         if (!$thumbnailType) {
             $thumbnailType = 'png';
         }
     }
     foreach ($options['thumbnailSizes'] as $size => $geometry) {
         $fileName = str_replace(array('{size}', '{filename}'), array($size, $pathInfo['filename']), $options['thumbnailName']);
         $thumbnailPath = $options['thumbnailPath'];
         $thumbnailPath = $this->_pathThumbnail($model, $field, compact('geometry', 'size', 'thumbnailPath'));
         $thumbnailFilePath = "{$thumbnailPath}{$dir}{$DS}{$fileName}.{$thumbnailType}";
         $this->__filesToRemove[$model->alias][] = $thumbnailFilePath;
     }
     return $this->__filesToRemove;
 }
开发者ID:ryantology,项目名称:upload,代码行数:56,代码来源:upload.php


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