public function thumbnail($img, $width, $height, $outputFormat = null, $targetPath = null)
    {
        if ($targetPath && $this->cache->cached($targetPath)) {
            return;
        }

        list($ow, $oh) = $imgInfo = ImageFile::getSize($img);
        $srcImg = ImageFile::get($img, $imgInfo);

        // calculate new size
        $or = $ow / $oh;
        $nr = $width / $height;

        if ($or > $nr) {
            $nh = $height;
            $nw = round($nh * $or);
        } else {
            $nw = $width;
            $nh = round($nw / $or);
        }

        $posX = ($nw - $width) / 2;
        $posY = ($nh - $height) / 2;

        // save
        $tmpImg = $this->resample($srcImg, $nw, $nh, $ow, $oh, $imgInfo);
        $dstImg = $this->copy($tmpImg, $width, $height, $width, $height, $imgInfo, 0, 0, $posX, $posY);

        ImageFile::save($targetPath ?: $img, $dstImg, ImageFile::getType($img, $outputFormat, $imgInfo));
        ImageFile::clean(array(&$dstImg, &$srcImg));
    }
public function thumbnail($img, $width, $height, $outputFormat = null, $targetPath = null)
    {
        if ($targetPath && $this->cache->cached($targetPath)) {
            return;
        }

        list($ow, $oh) = $imgInfo = ImageFile::getSize($img);
        $srcImg = ImageFile::get($img, $imgInfo);

        // calculate new size
        $or = $ow / $oh;
        $nr = $width / $height;

        if ($or > $nr) {
            $nh = $height;
            $nw = round($nh * $or);
        } else {
            $nw = $width;
            $nh = round($nw / $or);
        }

        $posX = ($nw - $width) / 2;
        $posY = ($nh - $height) / 2;

        // save
        $tmpImg = $this->resample($srcImg, $nw, $nh, $ow, $oh, $imgInfo);
        $dstImg = $this->copy($tmpImg, $width, $height, $width, $height, $imgInfo, 0, 0, $posX, $posY);

        ImageFile::save($targetPath ?: $img, $dstImg, ImageFile::getType($img, $outputFormat, $imgInfo));
        ImageFile::clean(array(&$dstImg, &$srcImg));
    }
public function thumbnail ( $ img , $ width , $ height , $ outputFormat = null , $ targetPath = null ) { if ( $ targetPath && $ this -> cache -> cached ( $ targetPath ) ) { return ; } list ( $ ow , $ oh ) = $ imgInfo = ImageFile :: getSize ( $ img ) ; $ srcImg = ImageFile :: get ( $ img , $ imgInfo ) ; // calculate new size $ or = $ ow / $ oh ; $ nr = $ width / $ height ; if ( $ or > $ nr ) { $ nh = $ height ; $ nw = round ( $ nh * $ or ) ; } else { $ nw = $ width ; $ nh = round ( $ nw / $ or ) ; } $ posX = ( $ nw - $ width ) / 2 ; $ posY = ( $ nh - $ height ) / 2 ; // save $ tmpImg = $ this -> resample ( $ srcImg , $ nw , $ nh , $ ow , $ oh , $ imgInfo ) ; $ dstImg = $ this -> copy ( $ tmpImg , $ width , $ height , $ width , $ height , $ imgInfo , 0 , 0 , $ posX , $ posY ) ; ImageFile :: save ( $ targetPath ? : $ img , $ dstImg , ImageFile :: getType ( $ img , $ outputFormat , $ imgInfo ) ) ; ImageFile :: clean ( array ( & $ dstImg , & $ srcImg ) ) ; }
Make a thumbnail by cropping the image by its shortest dimension

@param string $img
@param int $width
@param int $height
@param null|"jpeg"|"jpg"|"png"|"gif"|"wbmp"|"bmp"|"webp" $outputFormat - if null, it won't change
@param null|string $targetPath - if null, $img will be used
@throws FileException
Make a thumbnail by cropping the image by its shortest dimension