magento2: Magento 2.4.4 does not support .webp upload
Preconditions and environment
- Magento 2.4.4
We currently have our own API set up to connect to Magento, and we provide content from this; including images. This includes various mime types, including webp.
Whenever we try to send that image through the Magento REST API, it says it does not support the mime type.
We have also tried uploading an image in the magento admin page for:
- Catalog -> Products -> Product -> Image Gallery -> Upload
- Content -> Page -> Insert Image -> Upload
Steps to reproduce
Below the steps to reproduce the issue with the REST API:
- Set up Rest API
- Send .webp image to the REST API as base64 through http://my.magento.com/rest/all/V1/products/{id}/media
{
"entry": {
"media_type": "image",
"label": "My WEBP Image",
"position": "3",
"disabled": false,
"types": [],
"content": {
"base64_encoded_data": "................",
"type": "image/webp",
"name": "WebP_Logo.webp"
}
}
}
Expected result
Image is added to the gallery of the specified product.
Actual result
Error 400 Bad Request: {"message":"The image MIME type is not valid or not supported."}
.
On API Call: |POST| http://my.magento.com/rest/all/V1/products/{id}/media
Additional information
Magento\Framework\Api\ImageContentValidator
has the following allowed mime types:
private $defaultMimeTypes = [
'image/jpg',
'image/jpeg',
'image/gif',
'image/png',
];
There are other classes that have this same list of $defaultMimeTypes and $allowedMimeTypes.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 8
- Comments: 16 (6 by maintainers)
We should add support for avif too, even if avif is not supported everywhere yet. Let’s anticipate. https://caniuse.com/?search=avif
Also,
jxl
… We’re far from global support, but it seems even more promising than avif (https://avif.io/blog/comparisons/avif-vs-jpegxl/ - https://caniuse.com/?search=jxl)Hi @Toinehaaijer ,
Thanks for your contribution and collaboration. On basis of your use case marking this ticket as feature request.
Thanks
Hello!, I’m having problems adding webp images, and I was looking for solutions until I found this post, any news? I have tried to hardcode the code since as I have seen, compatibility by php in the magento code is included, but in the core of it it seems that it only supports jpg and png, adding webp does not work, as expected, like this I’m here to see who can think of something.
EDIT:
Im find this extension: https://github.com/MagestyApps/module-web-images
It works for me, it allows me to upload webp images and import products with .webp images.
The other huge reason is the filesize. I have a project that has just about 210K products, with a total size of images: 256Gb. So apart from talking about web performance, we should also talk about storage performance. I am in the process of importing the catalog, but I have a huge problem with available disk space. On my local dev server it’s not an issue, but on a staging server or even production, disk space is quite a premium.
I have PNG and JPG images 800 x 800 with filesizes 1.1mb. Converting to webp with quality 80, reduces the filesize to 76k without losing the resolution. So this begs the question, why would I not favor uploading webp natively, smaller images (filesize-wise), instead of huge png or jpg images?
I am in the process of batch converting all the images to webp to see the outcome. I am also doing the same experiment with png/jpg files, but reducing the resolution of all images > 300 in width to 300 max width, while maintaining aspect ratio. The latter expeiment is not ideal, because I would prefer a reduction in filesize while maintaining high resolution, i.e. webp.
Let’s keep in mid that images are by default uploaded to pub/media/catalog, in the same directory as the Magento instance resides. Magmi does the same thing. Therefore, using 3rd party modules is of no immediate benefit, because they convert to webp on the fly already uploaded png/jpg files.
The situation gets more complicated if you wish to use S3 or [Cloudflare] R2, 256Gb worth of images is quite expensive and not all merchants can afford the costs for large cloud based storage.
The right solution would be to allow webp uploading natively in Magento, and support it natively. My 2c worth.
I am using Magento 2.4.6-p2 CE.
@magento I am working on this