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

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

        if ($width == $ow) {
            if ($targetPath) {
                ImageFile::save($targetPath, $srcImg, ImageFile::getType($img, $outputFormat, $imgInfo));
            }
            return;
        }

        // calculate new size
        $nw = $width;
        $nh = round(($nw / $ow) * $oh);

        // save
        $dstImg = $this->resample($srcImg, $nw, $nh, $ow, $oh, $imgInfo);

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

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

        if ($width == $ow) {
            if ($targetPath) {
                ImageFile::save($targetPath, $srcImg, ImageFile::getType($img, $outputFormat, $imgInfo));
            }
            return;
        }

        // calculate new size
        $nw = $width;
        $nh = round(($nw / $ow) * $oh);

        // save
        $dstImg = $this->resample($srcImg, $nw, $nh, $ow, $oh, $imgInfo);

        ImageFile::save($targetPath ?: $img, $dstImg, ImageFile::getType($img, $outputFormat, $imgInfo));
        ImageFile::clean(array(&$dstImg, &$srcImg));
    }
public function widen ( $ img , $ width , $ outputFormat = null , $ targetPath = null ) { if ( $ targetPath && $ this -> cache -> cached ( $ targetPath ) ) { return ; } list ( $ ow , $ oh ) = $ imgInfo = ImageFile :: getSize ( $ img ) ; $ srcImg = ImageFile :: get ( $ img , $ imgInfo ) ; if ( $ width == $ ow ) { if ( $ targetPath ) { ImageFile :: save ( $ targetPath , $ srcImg , ImageFile :: getType ( $ img , $ outputFormat , $ imgInfo ) ) ; } return ; } // calculate new size $ nw = $ width ; $ nh = round ( ( $ nw / $ ow ) * $ oh ) ; // save $ dstImg = $ this -> resample ( $ srcImg , $ nw , $ nh , $ ow , $ oh , $ imgInfo ) ; ImageFile :: save ( $ targetPath ? : $ img , $ dstImg , ImageFile :: getType ( $ img , $ outputFormat , $ imgInfo ) ) ; ImageFile :: clean ( array ( & $ dstImg , & $ srcImg ) ) ; }
Set an image to the given width while preserving its ratio

@param string $img
@param int $width
@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
Set an image to the given width while preserving its ratio