oc-imageresizer-plugin
oc-imageresizer-plugin copied to clipboard
Allows to use remote images
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) }}" />
I know it's a radical idea, let me know any comments ...