public static function resize($options = null)
    {
        $options = Helper::getOptions($options, [
            "fromPath"  =>  null,
            "toPath"    =>  null,
            "width"     =>  null,
            "height"    =>  null,
        ]);

        if (!$fromPath = trim($options["fromPath"])) {
            throw new \Exception("No from path specified to read from");
        }
        if (!$toPath = trim($options["toPath"])) {
            throw new \Exception("No to path specified to save to");
        }
        $maxWidth = round($options["width"]);
        $maxHeight = round($options["height"]);

        list($width, $height, $format) = getimagesize($fromPath);

        if ($width < 1 || $height < 1) {
            copy($fromPath, $toPath);
            return;
        }

        if ($maxWidth < 1 && $maxHeight < 1) {
            copy($fromPath, $toPath);
            return;
        }

        if ($width < $maxWidth && $height < $maxHeight) {
            copy($fromPath, $toPath);
            return;
        }

        $newWidth = $width;
        $newHeight = $height;

        if ($maxHeight && $newHeight > $maxHeight) {
            $ratio = $newWidth / $newHeight;
            $newHeight = $maxHeight;
            $newWidth = $newHeight * $ratio;
        }

        if ($maxWidth && $newWidth > $maxWidth) {
            $ratio = $newHeight / $newWidth;
            $newWidth = $maxWidth;
            $newHeight = $newWidth * $ratio;
        }

        $image = static::create($fromPath, $format);
        $newImage = imagecreatetruecolor($newWidth, $newHeight);

        if ($format != IMAGETYPE_JPEG) {
            imagealphablending($newImage, false);
            imagesavealpha($newImage, true);
            $background = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
            imagecolortransparent($newImage, $background);
        }

        imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
        static::save($newImage, $toPath, $format);

        imagedestroy($image);
        imagedestroy($newImage);
    }
public static function resize($options = null)
    {
        $options = Helper::getOptions($options, [
            "fromPath"  =>  null,
            "toPath"    =>  null,
            "width"     =>  null,
            "height"    =>  null,
        ]);

        if (!$fromPath = trim($options["fromPath"])) {
            throw new \Exception("No from path specified to read from");
        }
        if (!$toPath = trim($options["toPath"])) {
            throw new \Exception("No to path specified to save to");
        }
        $maxWidth = round($options["width"]);
        $maxHeight = round($options["height"]);

        list($width, $height, $format) = getimagesize($fromPath);

        if ($width < 1 || $height < 1) {
            copy($fromPath, $toPath);
            return;
        }

        if ($maxWidth < 1 && $maxHeight < 1) {
            copy($fromPath, $toPath);
            return;
        }

        if ($width < $maxWidth && $height < $maxHeight) {
            copy($fromPath, $toPath);
            return;
        }

        $newWidth = $width;
        $newHeight = $height;

        if ($maxHeight && $newHeight > $maxHeight) {
            $ratio = $newWidth / $newHeight;
            $newHeight = $maxHeight;
            $newWidth = $newHeight * $ratio;
        }

        if ($maxWidth && $newWidth > $maxWidth) {
            $ratio = $newHeight / $newWidth;
            $newWidth = $maxWidth;
            $newHeight = $newWidth * $ratio;
        }

        $image = static::create($fromPath, $format);
        $newImage = imagecreatetruecolor($newWidth, $newHeight);

        if ($format != IMAGETYPE_JPEG) {
            imagealphablending($newImage, false);
            imagesavealpha($newImage, true);
            $background = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
            imagecolortransparent($newImage, $background);
        }

        imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
        static::save($newImage, $toPath, $format);

        imagedestroy($image);
        imagedestroy($newImage);
    }
public static function resize ( $ options = null ) { $ options = Helper :: getOptions ( $ options , [ "fromPath" => null , "toPath" => null , "width" => null , "height" => null , ] ) ; if ( ! $ fromPath = trim ( $ options [ "fromPath" ] ) ) { throw new \ Exception ( "No from path specified to read from" ) ; } if ( ! $ toPath = trim ( $ options [ "toPath" ] ) ) { throw new \ Exception ( "No to path specified to save to" ) ; } $ maxWidth = round ( $ options [ "width" ] ) ; $ maxHeight = round ( $ options [ "height" ] ) ; list ( $ width , $ height , $ format ) = getimagesize ( $ fromPath ) ; if ( $ width < 1 || $ height < 1 ) { copy ( $ fromPath , $ toPath ) ; return ; } if ( $ maxWidth < 1 && $ maxHeight < 1 ) { copy ( $ fromPath , $ toPath ) ; return ; } if ( $ width < $ maxWidth && $ height < $ maxHeight ) { copy ( $ fromPath , $ toPath ) ; return ; } $ newWidth = $ width ; $ newHeight = $ height ; if ( $ maxHeight && $ newHeight > $ maxHeight ) { $ ratio = $ newWidth / $ newHeight ; $ newHeight = $ maxHeight ; $ newWidth = $ newHeight * $ ratio ; } if ( $ maxWidth && $ newWidth > $ maxWidth ) { $ ratio = $ newHeight / $ newWidth ; $ newWidth = $ maxWidth ; $ newHeight = $ newWidth * $ ratio ; } $ image = static :: create ( $ fromPath , $ format ) ; $ newImage = imagecreatetruecolor ( $ newWidth , $ newHeight ) ; if ( $ format != IMAGETYPE_JPEG ) { imagealphablending ( $ newImage , false ) ; imagesavealpha ( $ newImage , true ) ; $ background = imagecolorallocatealpha ( $ newImage , 255 , 255 , 255 , 127 ) ; imagecolortransparent ( $ newImage , $ background ) ; } imagecopyresampled ( $ newImage , $ image , 0 , 0 , 0 , 0 , $ newWidth , $ newHeight , $ width , $ height ) ; static :: save ( $ newImage , $ toPath , $ format ) ; imagedestroy ( $ image ) ; imagedestroy ( $ newImage ) ; }
Resize an image, maintaining the same aspect ratio.
If the image is already an appropriate size then it is just copied.

$options:
- string "fromPath" The path of the current image file
- string "toPath" The path to save the resized image to
- int "width" The maximum width that the image can be
- int "height" The maximum height that the image can be

@param array $options An array of options (see above)

@return null
Resize an image maintaining the same aspect ratio . If the image is already an appropriate size then it is just copied .