resize() public method

If either param is set to zero, then that dimension will not be considered as a part of the resize. Additionally, if $this->options['resizeUp'] is set to true (false by default), then this function will also scale the image up to the maximum dimensions provided.
public resize ( integer $maxWidth, integer $maxHeight ) : GdThumb
$maxWidth integer The maximum width of the image in pixels
$maxHeight integer The maximum height of the image in pixels
return GdThumb
示例#1
0
文件: Image.php 项目: bkwld/croppa
 /**
  * Pad an image to desired dimensions. Moves the image into the center and fills the rest with given color.
  *
  * @param integer $width
  * @param integer $height
  * @param array $options
  * @return $this
  */
 public function pad($width, $height, $options)
 {
     if (!$height || !$width) {
         throw new Exception('Croppa: Pad option needs width and height');
     }
     $color = $options['pad'] ?: [255, 255, 255];
     $this->thumb->resize($width, $height)->pad($width, $height, $color);
     return $this;
 }
示例#2
0
 public function resizeFixedSize($width, $height, $color = '#FFFFFF', &$that)
 {
     $this->parentInstance = $that;
     $this->parentInstance->resize($width, $height);
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->newImage = $this->parentInstance->getOldImage();
     $this->options = $this->parentInstance->getOptions();
     $this->workingImage = imagecreatetruecolor($width, $height);
     imagealphablending($this->workingImage, true);
     $rgb = $this->hex2rgb($color, false);
     $colorToPaint = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], 0);
     imagefilledrectangle($this->workingImage, 0, 0, $width, $height, $colorToPaint);
     imagecopyresampled($this->workingImage, $this->newImage, intval(($width - $this->currentDimensions['width']) / 2), intval(($height - $this->currentDimensions['height']) / 2), 0, 0, $this->currentDimensions['width'], $this->currentDimensions['height'], $this->currentDimensions['width'], $this->currentDimensions['height']);
     $this->parentInstance->setOldImage($this->workingImage);
     $this->currentDimensions['width'] = $width;
     $this->currentDimensions['height'] = $height;
     $this->parentInstance->setCurrentDimensions($this->currentDimensions);
     return $that;
 }
示例#3
0
文件: Image.php 项目: usielc/croppa
 /**
  * Resize with no cropping
  *
  * @param integer $width 
  * @param integer $height
  * @return $this
  */
 public function resize($width, $height)
 {
     if ($width && $height) {
         $this->thumb->resize($width, $height);
     } else {
         if (!$width) {
             $this->thumb->resize(99999, $height);
         } else {
             if (!$height) {
                 $this->thumb->resize($width, 99999);
             }
         }
     }
     return $this;
 }
示例#4
0
 public static function createThumb($source, $dest = null, $width = 200, $height = 160, $mode = 'resize')
 {
     if (!class_exists('ThumbBase')) {
         require_once JPATH_SITE . '/plugins/system/jvhelper/libs/ThumbBase.inc.php';
     }
     if (!class_exists('GdThumb')) {
         require_once JPATH_SITE . '/plugins/system/jvhelper/libs/GdThumb.inc.php';
     }
     if (!$dest) {
         $dest = JPATH_SITE . '/images/jvthumb';
     }
     $size = @getimagesize($source);
     if (!is_array($size)) {
         return $source;
     }
     $replace = JURI::base(true) . '/';
     if (strpos($source, $replace) === 0) {
         $source = substr($source, strlen($replace));
     }
     if (preg_match('#http(s?):\\/\\/#', $source) && $source) {
         if (stripos($size['mime'], 'image') === 0) {
             $extension = substr($size['mime'], 6);
             if ($extension == 'jpeg') {
                 $extension = 'jpg';
             }
             $info = array('extension' => $extension, 'filename' => substr(base64_encode(json_encode($size)), 0, 10));
         } else {
             return $source;
         }
     } else {
         $source = JPATH_SITE . '/' . $source;
         $info = pathinfo($source);
     }
     // Resize path
     $path = $dest . "/{$mode}_{$width}_{$height}_{$info['filename']}.{$info['extension']}";
     if (!is_dir(dirname($path))) {
         JFolder::create(dirname($path));
         $index = "<html><body></body></html>";
         if (!JFile::write($path . '/' . 'index.html', $index)) {
             return;
         }
     }
     if (!is_file($path)) {
         // Resize
         $thumb = new GdThumb($source, array('jpegQuality' => 80));
         if ($mode == 'resize') {
             $thumb->resize($width, $height);
         }
         if ($mode == 'crop') {
             $thumb->cropFromCenter($width, $height);
         }
         $thumb->save($path, $info['extension']);
     }
     return self::toURL($path);
 }
示例#5
0
 public static function createThumb($source, $dest, $width, $height, $mode)
 {
     $size = @getimagesize($source);
     if (!is_array($size)) {
         return $source;
     }
     $replace = JURI::base(true) . '/';
     if (strpos($source, $replace) === 0) {
         $source = substr($source, strlen($replace));
     }
     if (preg_match('#http(s?):\\/\\/#', $source) && $source) {
         if (stripos($size['mime'], 'image') === 0) {
             $extension = substr($size['mime'], 6);
             if ($extension == 'jpeg') {
                 $extension = 'jpg';
             }
             $info = array('extension' => $extension, 'filename' => substr(base64_encode(json_encode($size)), 0, 10));
         } else {
             return $source;
         }
     } else {
         $source = JPATH_SITE . '/' . $source;
         $info = pathinfo($source);
     }
     // Resize path
     $path = $dest . "/{$mode}_{$width}_{$info['filename']}.{$info['extension']}";
     if (!is_dir(dirname($path))) {
         JFolder::create(dirname($path));
         $index = "<html><body></body></html>";
         if (!JFile::write($path . '/' . 'index.html', $index)) {
             return;
         }
     }
     if (!is_file($path)) {
         // Resize
         if ($mode == 'original') {
             JFile::copy($source, $path);
             return self::toURL($path);
         }
         $thumb = new GdThumb($source, array('jpegQuality' => 90));
         if ($mode == 'resize') {
             $thumb->resize($width, $height);
         }
         if ($mode == 'crop') {
             $thumb->cropFromCenter($width, $height);
         }
         $thumb->save($path, $info['extension']);
     }
     return self::toURL($path);
 }