Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lat4732's avatar
Level 12

Converting all images to .webp

Hey!

My customer asked me to convert all images used in the app to .webp format. The thing that confuses me is the lazyload that I'm using for all images. Will lazyload work with .webp formats and what can you suggest me to convert all images to .webp?

0 likes
8 replies
lat4732's avatar
Level 12

@Snapey Okay, I will easily convert all images to .webp with this command line tool but what about the lazyload? Will it work with .webp format? Also what about the uploading in .webp? There are many forms where users can upload photos in the app. How will these photos be converted to .webp?

lat4732's avatar
Level 12

@Snapey I see that this command line tool can't decode .svg files. I guess only .jpg, .jpeg, .png to .webp is supported. Any ideas what to do with the .svg images?

martinbean's avatar

@Laralex SVG is a vector graphics format. Formats like JPEG and WebP is a raster (bitmap) format.

lat4732's avatar
Level 12

@martinbean What can I do with the .svg images other than use an online svg to webp convertor?

Snapey's avatar

@Laralex explain to your customer that svg outperforms webp and the images are svg for a reason (can be scaled to any size without loss of fidelity)

Snapey's avatar

personally I think Lighthouse favours WebP too much - probably just to promote their own format.

I don't know of a way of converting uploads (which will be in png or jpg probably) into webp. It might be possible using exec to shell to the command line conversion tool, but the gains are probably not worth the energy

lat4732's avatar
Level 12

@Snapey Thanks for your opinion. My customer is categorical about converting everything to .webp. That's how you convert the uploaded image into .webp with Image Intervention

$webp_image = Image::make($request->image)->encode('webp', 90);
1 like

Please or to participate in this conversation.