magento2
magento2 copied to clipboard
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.
- [X] 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”.
Hi @Toinehaaijer. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance - upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Lima. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
-
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
Details
If the issue has a valid description, the labelIssue: Format is validwill be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is validappears. -
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Descriptionlabel to the issue by yourself. -
[ ] 3. Add
Component: XXXXXlabel(s) to the ticket, indicating the components it may be related to. -
[ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! -
[ ] 5. Add label
Issue: Confirmedonce verification is complete. -
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @Toinehaaijer ,
As per M2 document only JPG & PNG file format is supported.And webp file format is not supported. Kindly refer the devdocs for your reference.
Let us know if you are facing any issue with other file formats.
Thanks
@engcom-Lima Thanks, I couldn't find that part of the docs. Is it possible to turn webp compatibility into a feature request?
@Toinehaaijer I will discuss internally for your query then, I will come back to you as soon as possible.
Hi @Toinehaaijer
We want to know your use case for using webp type format? As I have seen some of the website not recommending that because some of the browser not suporting it, image thumbnail not was broken on there sites.
Thanks
Hi @engcom-Lima, our use case would be increasing performance/load times, as webp should be about 25%-34% smaller than a jpeg, and 26% smaller than a png. Also, it would increase flexibility for end users who don't really give file/mime types a second thought.
WEBP compatibility seems really good now, only IE (and KaiOS browser) don't support this: https://caniuse.com/webp
Hi @Toinehaaijer ,
Thanks for your contribution and collaboration. On basis of your use case marking this ticket as feature request.
Thanks
@Toinehaaijer You should use Yireo plugin for webp support: https://www.yireo.com/software/magento-extensions/webp2
@ananth-iyer Thanks, I've already looked at this plugin and it does add webp compatibility, but in a different way. It generates webp images based on jpg and png images you've added to the site.
The problems I have with this plugin:
- Webp upload is not supported (Both REST API and upload via admin doesn't support webp), so no extra flexibility
- Doesn't seem to work on a 2.4.4 install (composer rejects it because of the magento/framework version)
- Doesn't work with lazyloading images (which is usually used for performance reasons, which is the same reason you want webp)
- Extra server load + storage for the generated images (which is a given, but still).
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)
@magento I am working on this
It is 2023, we should have webp native support in magento already. https://caniuse.com/webp Is there a PR for this?
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)
I would vote not adding those format for now and leave them to 3rd party modules. They don't seem to be that commonly used
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.
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.