src/Painter.php
/**
     * Load an image from a given uri
     */
Load an image from a given uri
Load an image from a given uri
public function loadFromUri(string $uri, ?string $name = null) : bool
    {
        if (filter_var($uri, FILTER_VALIDATE_URL)) {
            $image     = getimagesize($uri);
            $extension = null;
            switch ($image['mime']) {
                case 'image/gif':
                    $extension = '.gif';
                    break;
                case 'image/png':
                    $extension = '.png';
                    break;
                case 'image/bmp':
                    $extension = '.bmp';
                    break;
                case 'image/jpeg':
                    $extension = '.jpg';
                    break;
                default:
                    return false;
            }
            if ($name === null) {
                $name = uniqid('img-') . $extension;
            } else {
                $name .= '-' . uniqid("", true) . $extension;
            }
            $tmp_path = sys_get_temp_dir() . '/';
            file_put_contents($tmp_path . $name, file_get_contents($uri));
            $this->loadFromFileSystem($tmp_path . $name);
        }
        return false;
    }
public function loadFromUri ( string $ uri , ? string $ name = null ) : bool { if ( filter_var ( $ uri , FILTER_VALIDATE_URL ) ) { $ image = getimagesize ( $ uri ) ; $ extension = null ; switch ( $ image [ 'mime' ] ) { case 'image/gif' : $ extension = '.gif' ; break ; case 'image/png' : $ extension = '.png' ; break ; case 'image/bmp' : $ extension = '.bmp' ; break ; case 'image/jpeg' : $ extension = '.jpg' ; break ; default : return false ; } if ( $ name === null ) { $ name = uniqid ( 'img-' ) . $ extension ; } else { $ name .= '-' . uniqid ( " " , true ) . $ extension ; } $ tmp_path = sys_get_temp_dir ( ) . '/' ; file_put_contents ( $ tmp_path . $ name , file_get_contents ( $ uri ) ) ; $ this -> loadFromFileSystem ( $ tmp_path . $ name ) ; } return false ; }
Load an image from a given uri
Load an image from a given uri