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


PHP WideImage_Image::crop方法代码示例

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


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

示例1:

 /**
  * Apply the manipulation with the setup options to the passed in image.
  * This does not do any memory manipulation
  *
  * @param WideImage_Image $image
  * @return WideImage_Image
  */
 public function &apply(WideImage_Image &$image)
 {
     if (!$this->isSetup()) {
         throw new RokGallery_Manipulation_Exception(rc__('ROKGALLERY_MANIPULATION_WAS_NOT_SETUP_PRIOR_TO_APPLYING'));
     }
     if ($this->left == 0 && $this->top == 0 && $this->width == 0 && $this->height == 0) {
         $this->width = $image->getWidth();
         $this->height = $image->getHeight();
     }
     $return_image = $image->crop($this->left, $this->top, $this->width, $this->height);
     return $return_image;
 }
开发者ID:atikahmed,项目名称:joomla-probid,代码行数:19,代码来源:Crop.php

示例2: execute

 /**
  * Executes the auto-crop operation on the $img
  * 
  * @param WideImage_Image $img 
  * @param int $rgb_threshold The difference in RGB from $base_color
  * @param int $pixel_cutoff The number of pixels on each border that must be over $rgb_threshold
  * @param int $base_color The color that will get cropped
  * @return WideImage_Image resulting auto-cropped image
  */
 function execute($img, $margin, $rgb_threshold, $pixel_cutoff, $base_color)
 {
     $margin = intval($margin);
     $rgb_threshold = intval($rgb_threshold);
     if ($rgb_threshold < 0) {
         $rgb_threshold = 0;
     }
     $pixel_cutoff = intval($pixel_cutoff);
     if ($pixel_cutoff <= 1) {
         $pixel_cutoff = 1;
     }
     if ($base_color === null) {
         $rgb_base = $img->getRGBAt(0, 0);
     } else {
         if ($base_color < 0) {
             return $img->copy();
         }
         $rgb_base = $img->getColorRGB($base_color);
     }
     $cut_rect = array('left' => 0, 'top' => 0, 'right' => $img->getWidth() - 1, 'bottom' => $img->getHeight() - 1);
     for ($y = 0; $y <= $cut_rect['bottom']; $y++) {
         $count = 0;
         for ($x = 0; $x <= $cut_rect['right']; $x++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['top'] = $y;
                     break 2;
                 }
             }
         }
     }
     for ($y = $img->getHeight() - 1; $y >= $cut_rect['top']; $y--) {
         $count = 0;
         for ($x = 0; $x <= $cut_rect['right']; $x++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['bottom'] = $y;
                     break 2;
                 }
             }
         }
     }
     for ($x = 0; $x <= $cut_rect['right']; $x++) {
         $count = 0;
         for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['left'] = $x;
                     break 2;
                 }
             }
         }
     }
     for ($x = $cut_rect['right']; $x >= $cut_rect['left']; $x--) {
         $count = 0;
         for ($y = $cut_rect['top']; $y <= $cut_rect['bottom']; $y++) {
             $rgb = $img->getRGBAt($x, $y);
             $diff = abs($rgb['red'] - $rgb_base['red']) + abs($rgb['green'] - $rgb_base['green']) + abs($rgb['blue'] - $rgb_base['blue']);
             if ($diff > $rgb_threshold) {
                 $count++;
                 if ($count >= $pixel_cutoff) {
                     $cut_rect['right'] = $x;
                     break 2;
                 }
             }
         }
     }
     $cut_rect = array('left' => $cut_rect['left'] - $margin, 'top' => $cut_rect['top'] - $margin, 'right' => $cut_rect['right'] + $margin, 'bottom' => $cut_rect['bottom'] + $margin);
     if ($cut_rect['left'] < 0) {
         $cut_rect['left'] = 0;
     }
     if ($cut_rect['top'] < 0) {
         $cut_rect['top'] = 0;
     }
     if ($cut_rect['right'] >= $img->getWidth()) {
         $cut_rect['right'] = $img->getWidth() - 1;
     }
     if ($cut_rect['bottom'] >= $img->getHeight()) {
         $cut_rect['bottom'] = $img->getHeight() - 1;
     }
     return $img->crop($cut_rect['left'], $cut_rect['top'], $cut_rect['right'] - $cut_rect['left'] + 1, $cut_rect['bottom'] - $cut_rect['top'] + 1);
 }
开发者ID:NaszvadiG,项目名称:DivaSul,代码行数:100,代码来源:AutoCrop.php

示例3: cropImage

 /**
  * Crops image
  *
  * @param int $left
  * @param int $top
  * @param int $width
  * @param int $height
  * 
  * @return UTIL_Image
  */
 public function cropImage($left, $top, $width, $height)
 {
     $this->image = $this->image->crop($left, $top, $width, $height);
     return $this;
 }
开发者ID:ZyXelP,项目名称:oxwall,代码行数:15,代码来源:image.php


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