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


PHP imagick::getImageGeometry方法代码示例

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


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

示例1: array

mkdir('./images/output');
$climate->Green("Comparing level is {$percent}%\n");
$climate->Green("Preparing to comparing...\n");
$progress = $climate->progress()->total(count($json->path));
$files = array();
$files_error = array();
foreach ($json->path as $path_key => $path) {
    $file1 = "./images/{$tag_one}/{$path_key}.png";
    $file2 = "./images/{$tag_two}/{$path_key}.png";
    chmod("./images/{$tag_one}", 0777);
    chmod("./images/{$tag_two}", 0777);
    $progress->current($path_key + 1, "Comparing between {$file1} and {$file2}");
    if (file_exists($file1) && file_exists($file2)) {
        $image1 = new imagick($file1);
        $image2 = new imagick($file2);
        $d1 = $image1->getImageGeometry();
        $w1 = $d1['width'];
        $h1 = $d1['height'];
        $d2 = $image2->getImageGeometry();
        $w2 = $d2['width'];
        $h2 = $d2['height'];
        if ($w1 == $w2 && $h1 == $h2) {
            $result = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR);
            if ($result[1] > $percent) {
                $result[0]->setImageFormat("png");
                $files[] = "{$path_key}.png";
                file_put_contents("./images/output/{$path_key}.png", $result[0]);
            }
        } else {
            $files_error[] = "Images {$file1} and {$file2} have different sizes";
        }
开发者ID:andrew-mikhailov,项目名称:watcher,代码行数:31,代码来源:compare.php

示例2: _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

示例3: resizeCropImg

 private function resizeCropImg($pFolder, $pImg, $pW, $pH)
 {
     $im = new imagick();
     $im->readImage($pFolder . $pImg);
     $image = new stdClass();
     $image->dimensions = $im->getImageGeometry();
     $image->w = $image->dimensions['width'];
     $image->h = $image->dimensions['height'];
     $image->ratio = $image->w / $image->h;
     if ($image->w / $pW < $image->h / $pH) {
         $h = ceil($pH * $image->w / $pW);
         $y = ($image->h - $pH * $image->w / $pW) / 2;
         $im->cropImage($image->w, $h, 0, $y);
     } else {
         $w = ceil($pW * $image->h / $pH);
         $x = ($image->w - $pW * $image->h / $pH) / 2;
         $im->cropImage($w, $image->h, $x, 0);
     }
     $im->ThumbnailImage($pW, $pH, true);
     if ($img->type === "PNG") {
         $im->setImageCompressionQuality(55);
         $im->setImageFormat('png');
     } elseif ($img->type === "JPG" || $img->type === "JPEG") {
         $im->setCompressionQuality(100);
         $im->setImageFormat("jpg");
     }
     $im->writeImage($this->ad->url->folder . '/assets/' . $pImg);
     $im->destroy();
 }
开发者ID:arnolali,项目名称:incontournables-du-voyage,代码行数:29,代码来源:Ad.php


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