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


PHP imagick::cropThumbnailImage方法代码示例

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


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

示例1: _resizeImg

 /**
  * Resize image
  *
  * @param  string  $img  image path
  * @param  int     $w    image width
  * @param  int     $h    image height
  * @return bool
  **/
 protected function _resizeImg($img, $w, $h)
 {
     if (false == ($s = getimagesize($img))) {
         return false;
     }
     switch ($this->_options['imgLib']) {
         case 'imagick':
             if (false != ($_img = new imagick($img))) {
                 return $_img->cropThumbnailImage($w, $h) && $_img->writeImage($img);
             }
             break;
         case 'mogrify':
             exec('mogrify -scale ' . $w . 'x' . $h . '! ' . escapeshellarg($img), $o, $c);
             return 0 == $c;
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $_img = imagecreatefromjpeg($img);
             } elseif ($s['mime'] = 'image/png') {
                 $_img = imagecreatefrompng($img);
             } elseif ($s['mime'] = 'image/gif') {
                 $_img = imagecreatefromgif($img);
             }
             if (!$_img || false == ($_out = imagecreatetruecolor($w, $h))) {
                 return false;
             }
             if (!imagecopyresampled($_out, $_img, 0, 0, 0, 0, $w, $h, $s[0], $s[1])) {
                 return false;
             }
             if ($s['mime'] == 'image/jpeg') {
                 $r = imagejpeg($_out, $img, 100);
             } else {
                 if ($s['mime'] = 'image/png') {
                     $r = imagepng($_out, $img, 7);
                 } else {
                     $r = imagegif($_out, $img, 7);
                 }
             }
             imagedestroy($_img);
             imagedestroy($_out);
             return $r;
             break;
     }
 }
开发者ID:hucongyang,项目名称:lulucms2,代码行数:52,代码来源:elFinder.class.php

示例2: cropImage_common

<?php

$case = "show_img";
//show_img, save_img
$cropThumbnailImage = true;
$filename = "img/" . $_GET["file"];
if (class_exists("imagick")) {
    $im = new imagick($filename);
    /* create the thumbnail */
    if ($cropThumbnailImage) {
        $im->cropThumbnailImage(80, 80);
    }
    /* Write to a file */
    if ($resizeImage) {
        $im->resizeImage(900, 80, 1, 0.5);
    }
    switch ($case) {
        case "write_img":
            $im->writeImage("img/" . $_GET["file"]);
            break;
        case "show_img":
            header("Content-Type: image/jpg");
            echo $im->getImageBlob();
            break;
    }
} else {
    cropImage_common($filename, 80, 80);
}
function cropImage_common($filename, $width, $height)
{
    // Content type
开发者ID:vihoangson,项目名称:Program_lesson,代码行数:31,代码来源:show_img.php

示例3: imagick

 function _resizeImagick(&$model, $field, $path, $size, $geometry, $thumbnailPath)
 {
     $srcFile = $path . $model->data[$model->alias][$field];
     $pathInfo = $this->_pathinfo($srcFile);
     $thumbnailType = $this->settings[$model->alias][$field]['thumbnailType'];
     $isMedia = $this->_isMedia($model, $this->runtime[$model->alias][$field]['type']);
     $image = new imagick();
     if ($isMedia) {
         $image->setResolution(300, 300);
         $srcFile = $srcFile . '[0]';
     }
     $image->readImage($srcFile);
     $height = $image->getImageHeight();
     $width = $image->getImageWidth();
     if (preg_match('/^\\[[\\d]+x[\\d]+\\]$/', $geometry)) {
         // resize with banding
         list($destW, $destH) = explode('x', substr($geometry, 1, strlen($geometry) - 2));
         $image->thumbnailImage($destW, $destH);
     } elseif (preg_match('/^[\\d]+x[\\d]+$/', $geometry)) {
         // cropped resize (best fit)
         list($destW, $destH) = explode('x', $geometry);
         $image->cropThumbnailImage($destW, $destH);
     } elseif (preg_match('/^[\\d]+w$/', $geometry)) {
         // calculate heigh according to aspect ratio
         $image->thumbnailImage((int) $geometry - 1, 0);
     } elseif (preg_match('/^[\\d]+h$/', $geometry)) {
         // calculate width according to aspect ratio
         $image->thumbnailImage(0, (int) $geometry - 1);
     } elseif (preg_match('/^[\\d]+l$/', $geometry)) {
         // calculate shortest side according to aspect ratio
         $destW = 0;
         $destH = 0;
         $destW = $width > $height ? (int) $geometry - 1 : 0;
         $destH = $width > $height ? 0 : (int) $geometry - 1;
         $imagickVersion = phpversion('imagick');
         $image->thumbnailImage($destW, $destH, !($imagickVersion[0] == 3));
     }
     if ($isMedia) {
         $thumbnailType = $this->settings[$model->alias][$field]['mediaThumbnailType'];
     }
     if (!$thumbnailType || !is_string($thumbnailType)) {
         try {
             $thumbnailType = $image->getImageFormat();
         } catch (Exception $e) {
             $thumbnailType = 'png';
         }
     }
     $fileName = str_replace(array('{size}', '{filename}'), array($size, $pathInfo['filename']), $this->settings[$model->alias][$field]['thumbnailName']);
     $destFile = "{$thumbnailPath}{$fileName}.{$thumbnailType}";
     $image->setImageCompressionQuality($this->settings[$model->alias][$field]['thumbnailQuality']);
     $image->setImageFormat($thumbnailType);
     if (!$image->writeImage($destFile)) {
         return false;
     }
     $image->clear();
     $image->destroy();
     return true;
 }
开发者ID:ryantology,项目名称:upload,代码行数:58,代码来源:upload.php

示例4: _resizeImagick

 public function _resizeImagick(Model $model, $field, $path, $size, $geometry, $thumbnailPath)
 {
     $srcFile = $path . $model->data[$model->alias][$field];
     $pathInfo = $this->_pathinfo($srcFile);
     $thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['thumbnailType'];
     $isMedia = $this->_isMedia($model, $this->runtime[$model->alias][$field]['type']);
     $image = new imagick();
     if ($isMedia) {
         $image->setResolution(300, 300);
         $srcFile = $srcFile . '[0]';
     }
     $image->readImage($srcFile);
     $height = $image->getImageHeight();
     $width = $image->getImageWidth();
     if (preg_match('/^\\[[\\d]+x[\\d]+\\]$/', $geometry)) {
         // resize with banding
         list($destW, $destH) = explode('x', substr($geometry, 1, strlen($geometry) - 2));
         $image->thumbnailImage($destW, $destH, true);
         $imageGeometry = $image->getImageGeometry();
         $x = ($imageGeometry['width'] - $destW) / 2;
         $y = ($imageGeometry['height'] - $destH) / 2;
         $image->setGravity(Imagick::GRAVITY_CENTER);
         $image->extentImage($destW, $destH, $x, $y);
     } elseif (preg_match('/^[\\d]+x[\\d]+$/', $geometry)) {
         // cropped resize (best fit)
         list($destW, $destH) = explode('x', $geometry);
         $image->cropThumbnailImage($destW, $destH);
     } elseif (preg_match('/^[\\d]+w$/', $geometry)) {
         // calculate heigh according to aspect ratio
         $image->thumbnailImage((int) $geometry - 1, 0);
     } elseif (preg_match('/^[\\d]+h$/', $geometry)) {
         // calculate width according to aspect ratio
         $image->thumbnailImage(0, (int) $geometry - 1);
     } elseif (preg_match('/^[\\d]+l$/', $geometry)) {
         // calculate shortest side according to aspect ratio
         $destW = 0;
         $destH = 0;
         $destW = $width > $height ? (int) $geometry - 1 : 0;
         $destH = $width > $height ? 0 : (int) $geometry - 1;
         $imagickVersion = phpversion('imagick');
         $image->thumbnailImage($destW, $destH, !($imagickVersion[0] == 3));
     }
     if ($isMedia) {
         $thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['mediaThumbnailType'];
     }
     if (!$thumbnailType || !is_string($thumbnailType)) {
         try {
             $thumbnailType = $imageFormat = $image->getImageFormat();
             // Fix file casing
             while (true) {
                 $ext = false;
                 $pieces = explode('.', $srcFile);
                 if (count($pieces) > 1) {
                     $ext = end($pieces);
                 }
                 if (!$ext || !strlen($ext)) {
                     break;
                 }
                 $low = array('ext' => strtolower($ext), 'thumbnailType' => strtolower($thumbnailType));
                 if ($low['ext'] == 'jpg' && $low['thumbnailType'] == 'jpeg') {
                     $thumbnailType = $ext;
                     break;
                 }
                 if ($low['ext'] == $low['thumbnailType']) {
                     $thumbnailType = $ext;
                 }
                 break;
             }
         } catch (Exception $e) {
             $this->log($e->getMessage(), 'upload');
             $thumbnailType = $imageFormat = 'png';
         }
     }
     $fileName = str_replace(array('{size}', '{filename}', '{primaryKey}'), array($size, $pathInfo['filename'], $model->id), $this->settings[$model->alias][$field]['thumbnailName']);
     $destFile = "{$thumbnailPath}{$fileName}.{$thumbnailType}";
     $image->setImageCompressionQuality($this->settings[$model->alias][$field]['thumbnailQuality']);
     $image->setImageFormat($imageFormat);
     if (!$image->writeImage($destFile)) {
         return false;
     }
     $image->clear();
     $image->destroy();
     return true;
 }
开发者ID:ederdsr,项目名称:civisindicadores,代码行数:84,代码来源:UploadBehavior.php

示例5: greateTH

 private function greateTH($file, $th)
 {
     $im = new imagick($_SERVER['DOCUMENT_ROOT'] . "/" . $file);
     $im->cropThumbnailImage(110, 110);
     $im->writeImage($_SERVER['DOCUMENT_ROOT'] . "/" . $th);
 }
开发者ID:pumi11,项目名称:veselkina,代码行数:6,代码来源:PostFile.class.php

示例6: resize

 public static function resize($orig_file_path, $settings, $target_file_path)
 {
     $quality = 95;
     $crop = $settings['crop_method'];
     $current_width = $settings['width'];
     $current_height = $settings['height'];
     $target_width = min($current_width, $settings['width_requested']);
     $target_height = min($current_height, $settings['height_requested']);
     if ($crop) {
         $x_ratio = $target_width / $current_width;
         $y_ratio = $target_height / $current_height;
         $ratio = min($x_ratio, $y_ratio);
         $use_x_ratio = $x_ratio == $ratio;
         $new_width = $use_x_ratio ? $target_width : floor($current_width * $ratio);
         $new_height = !$use_x_ratio ? $target_height : floor($current_height * $ratio);
     } else {
         $new_width = $target_width;
         $new_height = $target_height;
     }
     $im = new imagick($orig_file_path);
     $im->cropThumbnailImage($new_width, $new_height);
     $im->setImageCompression(imagick::COMPRESSION_JPEG);
     $im->setImageCompressionQuality($quality);
     $im->stripImage();
     $result = $im->writeImage($target_file_path);
     $im->destroy();
     return array($new_width, $new_height, $target_width, $target_height);
 }
开发者ID:rasstroen,项目名称:baby-album,代码行数:28,代码来源:ImgStore.php


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