public static function img($options = null)
    {
        $options = Helper::getOptions($options, [
            "path"      =>  "images/img",
            "basename"  =>  null,
            "filename"  =>  null,
            "width"     =>  null,
            "height"    =>  null,
        ]);

        $path = $options["path"];
        if ($path[0] == "/") {
            $fullpath = $path;
        } else {
            $fullpath = Env::path($path, Env::PATH_DOCUMENT_ROOT);
        }

        $filename = $options["filename"];
        if ($basename = $options["basename"]) {
            $original = $fullpath . "/original/" . $basename;
            if (file_exists($original)) {
                if ($ext = static::getExtension($original)) {
                    $filename = $basename . "." . $ext;
                    copy($original, $fullpath . "/original/" . $filename);
                }
            }
        }

        if (!$filename) {
            throw new \Exception("No image filename provided to use");
        }

        $original = $fullpath . "/original/" . $filename;
        if (!file_exists($original)) {
            throw new \Exception("Original image file does not exist (" . $original . ")");
        }

        $w = $options["width"];
        $h = $options["height"];

        if (!$w && !$h) {
            return $path . "/original/" . $filename;
        }

        if ($w && $h) {
            $dir = "max" . $w . "x" . $h;
        } elseif ($w) {
            $dir = "width" . $w;
        } elseif ($h) {
            $dir = "height" . $h;
        }

        $fullpath .= "/" . $dir;
        $newfile = $fullpath . "/" . $filename;
        $newpath = $path . "/" . $dir . "/" . $filename;

        if (file_exists($newfile)) {
            return $newpath;
        }

        if (!is_dir($fullpath)) {
            mkdir($fullpath, 0777, true);
        }

        static::resize([
            "fromPath"  =>  $original,
            "toPath"    =>  $newfile,
            "width"     =>  $w,
            "height"    =>  $h,
        ]);

        return $newpath;
    }
public static function img($options = null)
    {
        $options = Helper::getOptions($options, [
            "path"      =>  "images/img",
            "basename"  =>  null,
            "filename"  =>  null,
            "width"     =>  null,
            "height"    =>  null,
        ]);

        $path = $options["path"];
        if ($path[0] == "/") {
            $fullpath = $path;
        } else {
            $fullpath = Env::path($path, Env::PATH_DOCUMENT_ROOT);
        }

        $filename = $options["filename"];
        if ($basename = $options["basename"]) {
            $original = $fullpath . "/original/" . $basename;
            if (file_exists($original)) {
                if ($ext = static::getExtension($original)) {
                    $filename = $basename . "." . $ext;
                    copy($original, $fullpath . "/original/" . $filename);
                }
            }
        }

        if (!$filename) {
            throw new \Exception("No image filename provided to use");
        }

        $original = $fullpath . "/original/" . $filename;
        if (!file_exists($original)) {
            throw new \Exception("Original image file does not exist (" . $original . ")");
        }

        $w = $options["width"];
        $h = $options["height"];

        if (!$w && !$h) {
            return $path . "/original/" . $filename;
        }

        if ($w && $h) {
            $dir = "max" . $w . "x" . $h;
        } elseif ($w) {
            $dir = "width" . $w;
        } elseif ($h) {
            $dir = "height" . $h;
        }

        $fullpath .= "/" . $dir;
        $newfile = $fullpath . "/" . $filename;
        $newpath = $path . "/" . $dir . "/" . $filename;

        if (file_exists($newfile)) {
            return $newpath;
        }

        if (!is_dir($fullpath)) {
            mkdir($fullpath, 0777, true);
        }

        static::resize([
            "fromPath"  =>  $original,
            "toPath"    =>  $newfile,
            "width"     =>  $w,
            "height"    =>  $h,
        ]);

        return $newpath;
    }
public static function img ( $ options = null ) { $ options = Helper :: getOptions ( $ options , [ "path" => "images/img" , "basename" => null , "filename" => null , "width" => null , "height" => null , ] ) ; $ path = $ options [ "path" ] ; if ( $ path [ 0 ] == "/" ) { $ fullpath = $ path ; } else { $ fullpath = Env :: path ( $ path , Env :: PATH_DOCUMENT_ROOT ) ; } $ filename = $ options [ "filename" ] ; if ( $ basename = $ options [ "basename" ] ) { $ original = $ fullpath . "/original/" . $ basename ; if ( file_exists ( $ original ) ) { if ( $ ext = static :: getExtension ( $ original ) ) { $ filename = $ basename . "." . $ ext ; copy ( $ original , $ fullpath . "/original/" . $ filename ) ; } } } if ( ! $ filename ) { throw new \ Exception ( "No image filename provided to use" ) ; } $ original = $ fullpath . "/original/" . $ filename ; if ( ! file_exists ( $ original ) ) { throw new \ Exception ( "Original image file does not exist (" . $ original . ")" ) ; } $ w = $ options [ "width" ] ; $ h = $ options [ "height" ] ; if ( ! $ w && ! $ h ) { return $ path . "/original/" . $ filename ; } if ( $ w && $ h ) { $ dir = "max" . $ w . "x" . $ h ; } elseif ( $ w ) { $ dir = "width" . $ w ; } elseif ( $ h ) { $ dir = "height" . $ h ; } $ fullpath .= "/" . $ dir ; $ newfile = $ fullpath . "/" . $ filename ; $ newpath = $ path . "/" . $ dir . "/" . $ filename ; if ( file_exists ( $ newfile ) ) { return $ newpath ; } if ( ! is_dir ( $ fullpath ) ) { mkdir ( $ fullpath , 0777 , true ) ; } static :: resize ( [ "fromPath" => $ original , "toPath" => $ newfile , "width" => $ w , "height" => $ h , ] ) ; return $ newpath ; }
Automatically resize and create images on the fly.
If the image already exists then it's path is just passed back.

$options:
- string "path" The path that the images reside in (default: "images/img")
- string "basename" The filename, without extension, of the image, the extension will be automatically established and appended
- string "filename" The filename, including extension, of the image. Either this or "basename" must be set
- int "width" The maximum width that the image can be, if the image is wider it will be resized (maintaining the same aspect ratio)
- int "height" The maximum height that the image can be, if the image is taller it will be resized (maintaining the same aspect ratio)

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

@return string
Automatically resize and create images on the fly . If the image already exists then it s path is just passed back .