Generate the thumb by copying from $this->_source to $this->_thumb
resize from ($this->_sourceWidth, $this->_sourceHeight) to ($this->getThumbWidth(), $this->getThumbHeight())
359685
protected function _generateThumb()
        {
            $this->_initThumb(
                $this->_sourceWidth,
                $this->_sourceHeight,
                $this->_scale,
                $this->_inflate,
                $this->_maxWidth,
                $this->_maxHeight,
                $this->_minWidth,
                $this->_minHeight
            );

            $this->_newThumb($this->getThumbWidth(), $this->getThumbHeight());

            if ($this->_sourceWidth == $this->_maxWidth && $this->_sourceHeight == $this->_maxHeight) {
                $this->_thumb = $this->_source;
            } else {
                $this->_hasBeenModified = true;
                $this->_copyToThumb(
                    0,
                    0,
                    0,
                    0,
                    $this->getThumbWidth(),
                    $this->getThumbHeight(),
                    $this->_sourceWidth,
                    $this->_sourceHeight
                );
            }

            return $this;
        }
1248395
public function thumb($code = null, $width = 100, $height = 100, $mode = 'auto', $extension = 'auto')
    {
        try {
            return $this->findFileObject($code)->outputThumb(
                $width,
                $height,
                compact('mode', 'extension'),
                true
            );
        }
        catch (Exception $ex) {}

        return Response::make(View::make('backend::404'), 404);
    }
92601
public function resizeIn($maxWidth, $maxHeight, $minWidth = null, $minHeight = null)
        {
            $this->_maxWidth = $maxWidth;
            $this->_maxHeight = $maxHeight;
            $this->_minWidth = $minWidth;
            $this->_minHeight = $minHeight;

            $this->_generateThumb();

            $this->_source = $this->_thumb;
            $this->_reloadSize();

            return $this;
        }
1190764
public function buildThumb($width = null, $height = null)
    {
        /* @var Gallery $plugin */
        $plugin = $this->getTable()->getPlugin();

        $filename = $this->getPdoValue('image');
        $thumb = PhpThumbFactory::create($plugin->getDataDir() . '/' . $filename);

        $thumb->resize(
            $width ? $width : $plugin->settings['thumbWidth'],
            $height ? $height : $plugin->settings['thumbHeight']);
        $thumb->save($plugin->getDataDir() . '/' . $this->getPdoValue('thumb'));
    }
680468
public function create($image, $thumbnailWidth = 100, $thumbnailHeight = 100)
    {
        $this->setupTargetPath($image);
        $this->setupTargetImage($image);

        $this->transformation->thumbnail(new Image\Box($thumbnailWidth, $thumbnailHeight))
                             ->apply($this->imagine->open($image))
                             ->save($this->thumbnailImage);

        $this->imageSize = getimagesize($this->thumbnailImage);
    }
565087
protected function resizeCrop()
    {
        $sourceDimension = $this->sourceImageFile->getDimension();
        $resampleDimension = $this->resampleImageFile->getDimension();

        //try max width first...
        $resizeRatio = $resampleDimension->getWidth() / $sourceDimension->getWidth();
        $resizeWidth = $resampleDimension->getWidth();
        $resizeHeight = $sourceDimension->getHeight() * $resizeRatio;

        //if that didn't work
        if ($resizeHeight > $resampleDimension->getHeight()) {
            $resizeRatio = $resampleDimension->getHeight() / $sourceDimension->getHeight();
            $resizeHeight = $resampleDimension->getHeight();
            $resizeWidth = $sourceDimension->getWidth() * $resizeRatio;
        }

        $resampleImageResource =& $this->getResampleImageResource();

        if ($resampleDimension->getOrientation() === 'SQUARE') {

            try {

                $resampleImageResource->resizeimage($resizeWidth, $resizeHeight, \Gmagick::FILTER_LANCZOS, 0.9, false);
                $resampleAxis = new Dimension\Axis(
                    ($resizeWidth - $resampleDimension->getWidth()) / 2,
                    ($resizeHeight - $resampleDimension->getWidth()) / 2
                );

            } catch (\GmagickException $e) {

                $this->errors[ $e->getCode() ] = $e->getMessage();

                return false;

            }
        } else {
            switch ($resampleDimension->getFocus()) {
                default:
                case 'CENTER':
                    $resampleAxis = new Dimension\Axis(
                        ($sourceDimension->getWidth() / 2) - ($resizeWidth / 2),
                        ($sourceDimension->getHeight() / 2) - ($resizeHeight / 2)
                    );
                    break;
                case 'NORTH':
                    $resampleAxis = new Dimension\Axis(
                        ($sourceDimension->getWidth() - $resizeWidth) / 2,
                        0
                    );
                    break;
                case 'NORTHWEST':
                    $resampleAxis = new Dimension\Axis(
                        0,
                        0
                    );
                    break;
                case 'NORTHEAST':
                    $resampleAxis = new Dimension\Axis(
                        $sourceDimension->getWidth() - $resizeWidth,
                        0
                    );
                    break;
                case 'SOUTH':
                    $resampleAxis = new Dimension\Axis(
                        ($sourceDimension->getWidth() - $resizeWidth) / 2,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'SOUTHWEST':
                    $resampleAxis = new Dimension\Axis(
                        0,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'SOUTHEAST':
                    $resampleAxis = new Dimension\Axis(
                        $sourceDimension->getWidth() - $resizeWidth,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'WEST':
                    $resampleAxis = new Dimension\Axis(
                        0,
                        ($sourceDimension->getHeight() - $resizeHeight) / 2
                    );
                    break;
                case 'EAST':
                    $resampleAxis = new Dimension\Axis(
                        $sourceDimension->getWidth() - $resizeWidth,
                        ($sourceDimension->getHeight() - $resizeHeight) / 2
                    );
                    break;
            }

            try {

                $resampleImageResource->resizeimage($sourceDimension->getWidth(), $sourceDimension->getHeight(),
                    \Gmagick::FILTER_CATROM, 0.9, true);

            } catch (\GmagickException $e) {

                $this->errors[ $e->getCode() ] = $e->getMessage();

            }
        }

        return $this->crop($resampleDimension->withAxis($resampleAxis));
    }
361584
private function setThumbsDetails()
    {
        $this->thumbsDetails = [];
        if ($this->isImage()) {
            $service = new ThumbService($this->package);
            collect($service->getSizes())->each(function ($size, $key) {
                $this->thumbsDetails[$key] = [
                    'size' => $key,
                    'width' => $size[0],
                    'height' => $size[1],
                    'url' => $this->getUrl($key . '/' . $this->path)
                ];
            });
        }
    }
672251
def thumbnail!
      begin
        image = MiniMagick::Image.open(@file.path)
        image.resize("#{Pushfile.settings[:images][:thumb][:width]}x")
      rescue
        @thumb = nil
      else
        t = @name.split('.'); ext = t.pop
        @thumb = t.join(".").concat("_thumb.#{ext}")
        image.write("/tmp/#{@thumb}") rescue @thumb = nil
      end
    end
477574
public function resizeCrop()
    {
        $sourceDimension = $this->sourceImageFile->getDimension();
        $resampleDimension = $this->resampleImageFile->getDimension();

        if ($resampleDimension->getOrientation() === 'SQUARE') {
            if ($sourceDimension->getOrientation() === 'LANDSCAPE') {
                $sourceSquareSize = $sourceDimension->getHeight();

                $sourceDimension = new Dimension(
                    $sourceSquareSize,
                    $sourceSquareSize,
                    ($sourceDimension->getWidth() - $sourceDimension->getHeight()) / 2,
                    0
                );
            } elseif ($sourceDimension->getOrientation() === 'PORTRAIT') {
                $sourceSquareSize = $sourceDimension->getWidth();

                $sourceDimension = new Dimension(
                    $sourceSquareSize,
                    $sourceSquareSize,
                    0,
                    ($sourceDimension->getHeight() - $sourceDimension->getWidth()) / 2
                );
            }
        } else {

            //try max width first...
            $resizeRatio = $resampleDimension->getWidth() / $sourceDimension->getWidth();
            $resizeWidth = $resampleDimension->getWidth();
            $resizeHeight = $sourceDimension->getHeight() * $resizeRatio;

            //if that didn't work
            if ($resizeHeight > $resampleDimension->getHeight()) {
                $resizeRatio = $resampleDimension->getHeight() / $sourceDimension->getHeight();
                $resizeHeight = $resampleDimension->getHeight();
                $resizeWidth = $sourceDimension->getWidth() * $resizeRatio;
            }

            switch ($resampleDimension->getFocus()) {
                default:
                case 'CENTER':

                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        ($sourceDimension->getWidth() / 2) - ($resizeWidth / 2),
                        ($sourceDimension->getHeight() / 2) - ($resizeHeight / 2)
                    );

                    break;
                case 'NORTH':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        ($sourceDimension->getWidth() - $resizeWidth) / 2,
                        0
                    );
                    break;
                case 'NORTHWEST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        0,
                        0
                    );
                    break;
                case 'NORTHEAST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        $sourceDimension->getWidth() - $resizeWidth,
                        0
                    );
                    break;
                case 'SOUTH':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        ($sourceDimension->getWidth() - $resizeWidth) / 2,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'SOUTHWEST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        0,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'SOUTHEAST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        $sourceDimension->getWidth() - $resizeWidth,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'WEST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        0,
                        ($sourceDimension->getHeight() - $resizeHeight) / 2
                    );
                    break;
                case 'EAST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        $sourceDimension->getWidth() - $resizeWidth,
                        ($sourceDimension->getHeight() - $resizeHeight) / 2
                    );
                    break;
            }
        }

        $resampleAxis = $this->resampleImageFile->getDimension()->getAxis();
        $sourceAxis = $sourceDimension->getAxis();

        if (function_exists('imagecreatetruecolor')) {
            $this->resampleImageResource = imagecreatetruecolor(
                $resampleDimension->getWidth(),
                $resampleDimension->getHeight()
            );

            imagealphablending($this->resampleImageResource, false);
            imagesavealpha($this->resampleImageResource, true);

            $transparent = imagecolorallocatealpha($this->resampleImageResource, 255, 255, 255, 127);
            imagefilledrectangle($this->resampleImageResource, 0, 0, $resampleDimension->getWidth(),
                $resampleDimension->getHeight(), $transparent);

            return imagecopyresampled(
                $this->resampleImageResource,
                $this->sourceImageResource,
                $resampleAxis->getX(),
                $resampleAxis->getY(),
                $sourceAxis->getX(),
                $sourceAxis->getY(),
                $resampleDimension->getWidth(),
                $resampleDimension->getHeight(),
                $sourceDimension->getWidth(),
                $sourceDimension->getHeight()
            );
        } else {
            $this->resampleImageResource = imagecreate($resampleDimension->getWidth(),
                $resampleDimension->getHeight());

            imagealphablending($this->resampleImageResource, false);
            imagesavealpha($this->resampleImageResource, true);

            $transparent = imagecolorallocatealpha($this->resampleImageResource, 255, 255, 255, 127);
            imagefilledrectangle($this->resampleImageResource, 0, 0, $resampleDimension->getWidth(),
                $resampleDimension->getHeight(), $transparent);

            return imagecopyresized(
                $this->resampleImageResource,
                $this->sourceImageResource,
                $resampleAxis->getX(),
                $resampleAxis->getY(),
                $sourceAxis->getX(),
                $sourceAxis->getY(),
                $resampleDimension->getWidth(),
                $resampleDimension->getHeight(),
                $sourceDimension->getWidth(),
                $sourceDimension->getHeight()
            );
        }
    }
612605
private function getThumbnailUri(Thumbnail $thumb)
    {
        $fileName = $thumb->getFileName();
        if ($fileName === null || $fileName === '') {
            return false;
        }

        return $this->urlGenerator->generate(
            'thumb',
            [
                'width'  => $thumb->getWidth(),
                'height' => $thumb->getHeight(),
                'action' => $thumb->getScale(),
                'file'   => $thumb->getFileName(),
            ]
        );
    }
516554
public function imageCopyResampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
    {
        if($this->copyStrategy == self::RESIZE) {
            $this->log("Copy by resize");
            imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
        } else {
            $this->log("Copy by resample");
            imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
        }
    }
501670
protected function resize()
    {
        $config = config('image', true);

        if ( ! empty($this->imageQuality)) {
            $config->offsetSet('quality', intval($this->imageQuality));
        }

        if ($config->cached === true) {
            if ($this->imageFilePath !== $this->imageNotFoundFilename) {
                $cacheImageKey = 'image-' . ($this->input->get('crop') ? 'crop-' : '') . implode('x',
                        $this->imageSize) . '-' . str_replace($this->storagePath, '', $this->imageFilePath);

                if (cache()->hasItemPool('images')) {
                    $cacheItemPool = cache()->getItemPool('images');

                    if ($cacheItemPool->hasItem($cacheImageKey)) {
                        $cacheImageString = $cacheItemPool->getItem($cacheImageKey)->get();

                        $manipulation = new Manipulation($config);
                        $manipulation->setImageFile($this->imageFilePath);
                        $manipulation->setImageString($cacheImageString);
                        $manipulation->displayImage(intval($this->imageQuality), $this->imageFileMime);
                    } else {
                        $manipulation = new Manipulation($config);
                        $manipulation->setImageFile($this->imageFilePath);
                        $manipulation->resizeImage($this->imageSize[ 'width' ], $this->imageSize[ 'height' ],
                            (bool)$this->imageCrop);
                        $cacheItemPool->save(new Item($cacheImageKey, $manipulation->getBlobImage(), false));

                        $manipulation->displayImage(intval($this->imageQuality), $this->imageFileMime);
                        exit(EXIT_SUCCESS);
                    }
                }
            }
        }

        $manipulation = new Manipulation($config);
        $manipulation->setImageFile($this->imageFilePath);
        $manipulation->resizeImage($this->imageSize[ 'width' ], $this->imageSize[ 'height' ], (bool)$this->imageCrop);
        $manipulation->displayImage(intval($this->imageQuality), $this->imageFileMime);
        exit(EXIT_SUCCESS);
    }
1050444
protected function configure() {
		// set thumbnails path
		$path = $this->options['tmbPath'];
		if ($path) {
			if (!file_exists($path)) {
				if (@mkdir($path)) {
					chmod($path, $this->options['tmbPathMode']);
				} else {
					$path = '';
				}
			} 
			
			if (is_dir($path) && is_readable($path)) {
				$this->tmbPath = $path;
				$this->tmbPathWritable = is_writable($path);
			}
		}

		// set image manipulation library
		$type = preg_match('/^(imagick|gd|auto)$/i', $this->options['imgLib'])
			? strtolower($this->options['imgLib'])
			: 'auto';

		if (($type == 'imagick' || $type == 'auto') && extension_loaded('imagick')) {
			$this->imgLib = 'imagick';
		} else {
			$this->imgLib = function_exists('gd_info') ? 'gd' : '';
		}
		
	}
1237175
public function resize( $width = null, $height = null )
    {
        // Get the source width and height
        $sourceWidth = imagesx( $this->image );
        $sourceHeight = imagesy( $this->image );

        // Check if any of the width and height is null, and set it to the $source size
        // $width = $width ?: $sourceWidth;
        // $height = $height ?: $sourceHeight;
        $sourceAspectRatio = $sourceWidth / $sourceHeight;

        if ( !$width && !$height ) {
            $width = $sourceWidth;
            $height = $sourceHeight;
        }
        else if ( ! $width ) {
            $width = $height * $sourceAspectRatio;
        }
        else {
            $height = $width / $sourceAspectRatio;
        }

        $maxCanvasWidth = $width;
        $maxCanvasHeight = $height;

        $thumbnailAspectRatio = $maxCanvasWidth / $maxCanvasHeight;

        // Create canvas for the new image
        $canvas = $this->createCanvas( $width, $height );

        // Do the resizing of the image
        imagecopyresampled($canvas, $this->image, 0, 0, 0, 0, $width, $height, $sourceWidth, $sourceHeight);

        // Replace the current image
        $this->replace( $canvas );

        // Return this for linking
        return $this;
    }
365225
public function generate(string $resourceId, string $thumbId, $quality = 100)
    {
        $setting = $this->getThumbSettings($thumbId);

        $this->setThumbFolderName($setting);

        $resource = $this->getResource($resourceId);

        $file = $this->getOriginalFile($resource);

        if( $file ) {
            $image = $this->resizeImage($file, $setting);
//            $image = $this->addWatermark($image, $setting);
            $image->encode('jpg', $quality);
            $image->save($this->getLocation($resource));
        }
    }
559892
private function _calcThumbSize($imgWidth, $imgHeight, $thumbWidth, $thumbHeight, $thumbType)
    {
        //初始化缩略图尺寸
        $w = $thumbWidth;
        $h = $thumbHeight;

        //初始化原图尺寸
        $oldThumbWidth = $imgWidth;
        $oldThumbHeight = $imgHeight;

        // 原图比需要的缩略图还小
        if ($imgWidth <= $thumbWidth && $imgHeight <= $thumbHeight) {
            return [$imgWidth, $imgHeight, $oldThumbWidth, $oldThumbHeight];
        }

        switch ($thumbType) {
            case 1 :
                //固定宽度  高度自增
                $h = $thumbWidth / $imgWidth * $imgHeight;
                break;
            case 2 :
                //固定高度  宽度自增
                $w = $thumbHeight / $imgHeight * $imgWidth;
                break;
            case 3 :
                //固定宽度  高度裁切
                $oldThumbHeight = $imgWidth / $thumbWidth * $thumbHeight;
                break;
            case 4 :
                //固定高度  宽度裁切
                $oldThumbWidth = $imgHeight / $thumbHeight * $thumbWidth;
                break;
            case 5 :
                //缩放最大边 原图不裁切
                if (($imgWidth / $thumbWidth) > ($imgHeight / $thumbHeight)) {
                    $h = $thumbWidth / $imgWidth * $imgHeight;
                } else if (($imgWidth / $thumbWidth) < ($imgHeight / $thumbHeight)) {
                    $w = $thumbHeight / $imgHeight * $imgWidth;
                } else {
                    $w = $thumbWidth;
                    $h = $thumbHeight;
                }
                break;
            default:
                //缩略图尺寸不变，自动裁切图片
                if (($imgHeight / $thumbHeight) < ($imgWidth / $thumbWidth)) {
                    $oldThumbWidth = $imgHeight / $thumbHeight * $thumbWidth;
                } else if (($imgHeight / $thumbHeight) > ($imgWidth / $thumbWidth)) {
                    $oldThumbHeight = $imgWidth / $thumbWidth * $thumbHeight;
                }
        }

        return [$w, $h, $oldThumbWidth, $oldThumbHeight];
    }
10381
public function size(Int $width, Int $height) : Thumb
    {
        $this->sets['width']  = $width;
        $this->sets['height'] = $height;

        return $this;
    }