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

Allows to use remote images #76

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

skydiver
Copy link

@skydiver skydiver commented Dec 4, 2020

This PR allows to use remote images.

Note: there are 2 scenarios, depending if the url exposes the image extension or not

How it works:
When the class is initialized, we check if file path is a url.

In that case, we download the remote image to the storage folder (will be saved using the md5 of the url as filename).

After saving, we continue the normal resize/compression process using the local path.

If the URL doesn't expose the file extension, we try to discover by looking file mime type of downloaded file.

Because the plugin doesn't accept images without extension, we need to add the extension to the downloaded image (move from <image> to <image>.<extension>)

Next time image is requested, already downloaded file will be served.

How to use:

<img src="{{ 'https://images.unsplash.com/photo-1549880338-65ddcdfd017b'|resize(100) }}" />
<img src="{{ 'https://via.placeholder.com/300.png'|resize(100) }}" />
<img src="{{ 'https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80'|resize(100) }}" />

@skydiver
Copy link
Author

skydiver commented Dec 4, 2020

I know it's a radical idea, let me know any comments ...

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

Successfully merging this pull request may close these issues.

1 participant