src/S3/Image.php
public function getFromURL($url, $name = false)
    {
        $tmp_path = sys_get_temp_dir() . '/';

        if (Validator::validate(Validator::V_LINK, $url)) {
            $image = getimagesize($url);
            switch ($image['mime']) {
                case 'image/gif':
                case 'image/png':
                case 'image/bmp':
                case 'image/jpeg':
                    if ($image['mime'] == 'image/gif') {
                        $type = '.gif';
                    }
                    if ($image['mime'] == 'image/png') {
                        $type = '.png';
                    }
                    if ($image['mime'] == 'image/bmp') {
                        $type = '.bmp';
                    }
                    if ($image['mime'] == 'image/jpeg') {
                        $type = '.jpg';
                    }

                    if (!$name) {
                        $name = uniqid('post-') . $type;
                    } else {
                        $name .= '-' . uniqid("", true) . $type;
                    }
                    file_put_contents($tmp_path . $name, file_get_contents($url));

                    $this->getFromPath($name, sys_get_temp_dir());
                    $this->width  = $image[0];
                    $this->height = $image[1];

                    return true;
                default:
                    return false;
            }
        }

        return false;
    }
public function getFromURL($url, $name = false)
    {
        $tmp_path = sys_get_temp_dir() . '/';

        if (Validator::validate(Validator::V_LINK, $url)) {
            $image = getimagesize($url);
            switch ($image['mime']) {
                case 'image/gif':
                case 'image/png':
                case 'image/bmp':
                case 'image/jpeg':
                    if ($image['mime'] == 'image/gif') {
                        $type = '.gif';
                    }
                    if ($image['mime'] == 'image/png') {
                        $type = '.png';
                    }
                    if ($image['mime'] == 'image/bmp') {
                        $type = '.bmp';
                    }
                    if ($image['mime'] == 'image/jpeg') {
                        $type = '.jpg';
                    }

                    if (!$name) {
                        $name = uniqid('post-') . $type;
                    } else {
                        $name .= '-' . uniqid("", true) . $type;
                    }
                    file_put_contents($tmp_path . $name, file_get_contents($url));

                    $this->getFromPath($name, sys_get_temp_dir());
                    $this->width  = $image[0];
                    $this->height = $image[1];

                    return true;
                default:
                    return false;
            }
        }

        return false;
    }
public function getFromURL ( $ url , $ name = false ) { $ tmp_path = sys_get_temp_dir ( ) . '/' ; if ( Validator :: validate ( Validator :: V_LINK , $ url ) ) { $ image = getimagesize ( $ url ) ; switch ( $ image [ 'mime' ] ) { case 'image/gif' : case 'image/png' : case 'image/bmp' : case 'image/jpeg' : if ( $ image [ 'mime' ] == 'image/gif' ) { $ type = '.gif' ; } if ( $ image [ 'mime' ] == 'image/png' ) { $ type = '.png' ; } if ( $ image [ 'mime' ] == 'image/bmp' ) { $ type = '.bmp' ; } if ( $ image [ 'mime' ] == 'image/jpeg' ) { $ type = '.jpg' ; } if ( ! $ name ) { $ name = uniqid ( 'post-' ) . $ type ; } else { $ name .= '-' . uniqid ( "" , true ) . $ type ; } file_put_contents ( $ tmp_path . $ name , file_get_contents ( $ url ) ) ; $ this -> getFromPath ( $ name , sys_get_temp_dir ( ) ) ; $ this -> width = $ image [ 0 ] ; $ this -> height = $ image [ 1 ] ; return true ; default : return false ; } } return false ; }
Load an image from a given url

@param string $url  File url
@param bool   $name Optional name of the destiny file

@return bool
Load an image from a given url