Skip to content

Magento 2.4.4 does not support .webp upload #35836

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

Open
1 of 5 tasks
H-Toine opened this issue Jul 28, 2022 · 19 comments
Open
1 of 5 tasks

Magento 2.4.4 does not support .webp upload #35836

H-Toine opened this issue Jul 28, 2022 · 19 comments

Comments

@H-Toine
Copy link

H-Toine commented Jul 28, 2022

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
    vivaldi_Gtzkt5wu4P
  • Content -> Page -> Insert Image -> Upload
    vivaldi_KWKKvDOGgh

Steps to reproduce

Below the steps to reproduce the issue with the REST API:

  1. Set up Rest API
  2. 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”.
@m2-assistant
Copy link

m2-assistant bot commented Jul 28, 2022

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.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-assistant
Copy link

m2-assistant bot commented Jul 28, 2022

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Lima
Copy link
Contributor

engcom-Lima commented Jul 28, 2022

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 engcom-Lima added the Issue: needs update Additional information is require, waiting for response label Jul 28, 2022
@H-Toine
Copy link
Author

H-Toine commented Jul 28, 2022

@engcom-Lima Thanks, I couldn't find that part of the docs. Is it possible to turn webp compatibility into a feature request?

@engcom-Lima
Copy link
Contributor

@Toinehaaijer I will discuss internally for your query then, I will come back to you as soon as possible.

@engcom-Lima
Copy link
Contributor

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

@H-Toine
Copy link
Author

H-Toine commented Jul 28, 2022

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

@engcom-Lima
Copy link
Contributor

Hi @Toinehaaijer ,

Thanks for your contribution and collaboration.
On basis of your use case marking this ticket as feature request.

Thanks

@ananth-iyer
Copy link
Member

@Toinehaaijer You should use Yireo plugin for webp support: https://www.yireo.com/software/magento-extensions/webp2

@H-Toine
Copy link
Author

H-Toine commented Jul 29, 2022

@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).

@Nuranto
Copy link
Contributor

Nuranto commented Jul 29, 2022

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)

@sandy6666
Copy link
Contributor

@magento I am working on this

@ryansunxl
Copy link

It is 2023, we should have webp native support in magento already. https://caniuse.com/webp
Is there a PR for this?

@ryansunxl
Copy link

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

@xtremevision
Copy link

xtremevision commented Sep 2, 2023

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.

@antoniocastillomartinez
Copy link

antoniocastillomartinez commented Nov 16, 2023

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.

@zakdma
Copy link
Contributor

zakdma commented Jul 30, 2024

@antoniocastillomartinez sadly but it does not work for me. In admin I still see message
5.webp was not uploaded.
Disallowed file type.
Looks like Magento changed upload script so customization does not work now. So after I changed vendor/magento/module-backend/view/adminhtml/web/js/media-uploader.js by adding webp and svg to allowedExt variable it started working.

@ssSFrankSss
Copy link

Now we have 2025 are you planning to support webp format? I am interested in that too...

@pogo84
Copy link

pogo84 commented Jan 28, 2025

no they won't cause they sell modules for that ;) no webp upload from backend and no api uploads... shame

@engcom-Bravo engcom-Bravo removed the Issue: needs update Additional information is require, waiting for response label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests