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


PHP Thumbnail::crop方法代码示例

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


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

示例1: manipulate

 /**
  * Perfoms manipulation
  *
  * @param string $from
  * @param string $to
  * @param string $options
  * @return void
  */
 public function manipulate($from, $to, $options)
 {
     if (false === class_exists('Thumbnail')) {
         throw new Yag_Manipulator_Adapter_Exception('Class Thumbnail could not be loaded');
     }
     if (!isset($options['geometry'])) {
         throw new Yag_Manipulator_Adapter_Exception('Thumbnail requires the \'geometry\' option to be set');
     }
     $matches = array();
     preg_match('/(c)?([0-9]+)x([0-9]+)/', $options['geometry'], $matches);
     $crop = empty($matches[1]) ? false : true;
     $width = $matches[2];
     $height = $matches[3];
     if (empty($matches[2])) {
         throw new Yag_Manipulator_Adapter_Exception('Invalid geometry pattern \'' . $options['geometry'] . '\'');
     }
     if (empty($matches[3])) {
         throw new Yag_Manipulator_Adapter_Exception('Invalid geometry pattern \'' . $options['geometry'] . '\'');
     }
     $thumbnail = new Thumbnail($from);
     // TODO: Fix error handling around this...
     $quality = 80;
     if (false == $crop) {
         $thumbnail->resize($width, $height);
         $quality = 100;
     } else {
         if ($width == $height) {
             // Well works for now... the crop for ImageTransform is a bit better
             // but who cares?
             $thumbnail->cropFromCenter($width);
         } else {
             $thumbnail->crop(0, 0, $width, $height);
         }
     }
     $thumbnail->save($to, $quality);
 }
开发者ID:johannilsson,项目名称:yag,代码行数:44,代码来源:Thumbnail.php

示例2: crop

 function crop($imagePath, $thumbnailPath, $dimensions)
 {
     $crop = false;
     $newSize = trim(intval($dimensions[0])) > 0 ? trim(intval($dimensions[0])) : 100;
     $thumb = new Thumbnail($imagePath);
     if ($thumb->error) {
         echo $imagePath . ":" . $thumb->errmsg . "<br />";
         return false;
     }
     $minLength = min($thumb->getCurrentWidth(), $thumb->getCurrentHeight());
     $maxLength = max($thumb->getCurrentWidth(), $thumb->getCurrentHeight());
     // Image is smaller than the specified size so we just rename it and save
     if ($maxLength <= $newSize) {
         $thumb->save($thumbnailPath, $this->quality);
         //Just rename and save without processing
     } else {
         // At least one side is larger than specified thumbnail size
         // Both sides are larger than resize length so first we scale and if image is not square we crop
         if ($minLength > $newSize) {
             // Scale smaller size to desired new size
             if ($thumb->getCurrentWidth() < $thumb->getCurrentHeight()) {
                 $thumb->resize($newSize, 0);
                 $crop = true;
             } elseif ($thumb->getCurrentWidth() > $thumb->getCurrentHeight()) {
                 $thumb->resize(0, $newSize);
                 $crop = true;
             } else {
                 $thumb->resize($newSize, $newSize);
             }
             if ($crop) {
                 $thumb->cropFromCenter($newSize);
             }
             // One size is smaller than the new size, so we only crop the larger size to the new size
         } else {
             $cropX = intval(($thumb->getCurrentWidth() - $newSize) / 2);
             $cropY = intval(($thumb->getCurrentHeight() - $newSize) / 2);
             $thumb->crop($cropX, $cropY, $newSize, $newSize);
         }
         $thumb->save($thumbnailPath, $this->quality);
     }
     $thumb->destruct();
     if (file_exists($thumbnailPath)) {
         return true;
     }
     return false;
 }
开发者ID:bizanto,项目名称:Hooked,代码行数:46,代码来源:thumbnail.php


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