Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open image from an external URL #170

Open
vasileios-tsakalis opened this issue Oct 2, 2020 · 3 comments
Open

Open image from an external URL #170

vasileios-tsakalis opened this issue Oct 2, 2020 · 3 comments

Comments

@vasileios-tsakalis
Copy link

Is it possible to open an image from an external source, e.g. an API and then resize it.

@thedevale
Copy link

I agree, needing this too

@garygreen
Copy link
Contributor

This would be outside scope of this library imo.

Just use file_get_contents(), or curl, or guzzle, then pass onto gregwar.

@basteyy
Copy link

basteyy commented Jun 18, 2021

To download a file, you should use a proper library instead of using just file_get_contents. Think about authentications. From my point of view, it's not purposeful to implement such this kind of library in this package.

I would suggest to create a class like:

class DownloadAndDoStuff {

    private function _download(string $remote_image_url, string $local_path = null) {

        if(null === $local_path ) {
            $local_path = dirname(__DIR__);
        }

        $file = curl_file_create($local_path);
        $curl = new anlutro\cURL\cURL;
        $response = $curl->rawPost($remote_image_url, ['file' => $file]);

        return $local_path;
    }

    public function resizeImage(string $remote_image_url) {
        if(!isset($this->remoteFiles[$remote_image_url])) {
            $this->remoteFiles[$remote_image_url] = $this->_download($remote_image_url);
        }

        // File should be here: $this->remoteFiles[$remote_image_url]  do whatever you want

    }

    public function cropImage(string $remote_image_url) {
        if(!isset($this->remoteFiles[$remote_image_url])) {
            $this->remoteFiles[$remote_image_url] = $this->_download($remote_image_url);
        }

        // File should be here: $this->remoteFiles[$remote_image_url]  do whatever you want

    }

    public function flipImage(string $remote_image_url) {
        if(!isset($this->remoteFiles[$remote_image_url])) {
            $this->remoteFiles[$remote_image_url] = $this->_download($remote_image_url);
        }

        // File should be here: $this->remoteFiles[$remote_image_url]  do whatever you want
    }
}

see https://github.com/anlutro/php-curl for more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants