magento / community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46 stars 18 forks source link

Image Resizer should be in Core #320

Open in-session opened 3 years ago

in-session commented 3 years ago

Hello together,

it is really a tiresome topic to reduce images in template or modules to a certain size. There are countless helpers that would not be necessary if this was already in the core.

<?= $this->getViewFileUrl('Magento_Theme::images/big.jpg'); ?>
https://www.domain.de/static/version/frontend/vendor/store/en_EN/Magento_Theme/images/big.jpg

As a rough example

<?= $this->getViewFileUrlAndResize('Magento_Theme::images','50','50','big.jpg'); ?>
https://www.domain.de/static/version/frontend/vendor/store/en_EN/Magento_Theme/images/50x50/big.jpg

Thus it would be at least possible to reduce the images on each module simply

m2-assistant[bot] commented 3 years ago

Hi @in-session. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


in-session commented 3 years ago

It would be a simplification for everyone to implement something like this instead of using a helper for it every time. Also it would simplify some things with the cooperation of external modules, as an example, most modules for image compression or webp converting works on media folder base. Accordingly, static images are not converted, with this solution it would also be possible to insert images within the template.

Maybe as an idea:

<?= $this->getViewImageUrl('Magento_Theme::images/big.jpg'); ?>
https://www.domain.com/media/cache/{{Theme Path}}/Magento_Theme/images/big.jpg

<?= $this->getViewImageUrlAndResize('Magento_Theme::images','50','50','big.jpg'); ?>
https://www.domain.com/media/cache/{{Theme Path}}/Magento_Theme/images/resized/big-50x50.jpg
https://www.domain.com/media/cache/{{Theme Path}}/{{Modul}}/{{path}}/resized/big-{{size}}.jpg

In this case the images would be cloned or resized from themfolder to media. This would have significant advantages, the images always refer to the respective store and the original image is not changed.

Similarly it would go for all other modules as well as external modules:

<?= $this->getViewImageUrlAndResize('Vendor_Modul::images','50','50','big.jpg'); ?>
https://www.domain.com/media/cache/{{Theme Path}}/'Vendor_Modul/images/resized/big-50x50.jpg

Critical images that should remain in static can still be accessed and are excluded from it

<?= $this->getViewFileUrl('Magento_Theme::images/big.jpg'); ?>

You could clear the images using cache via admin, maybe additionally with a dropdown for selecting the store: Ashampoo_Snap_Montag, 8  März 2021_10h46m13s_037_

Here was once an approach to this:

Similar approach: