Search code examples
phpimagewebp

How to create a .webp image in PHP


How do you create .webp images using PHP?

Modern versions of PHP (>= 5.5.0) can be compiled with WebP support but from I've seen this isn't common on many web hosts. If compiled with WebP support you can use the built-in imagewebp() function to create .webp images.

What are the alternatives for creating .webp images using PHP? Libraries, APIs other methods?


Solution

  • The options currently available are: gd (extension), imagick (extension), imagick (exec-call), gmagick (extension), gmagick (exec-call), cwebp (exec-call), gmagick (exec call) or calling a cloud service. I have created a library 'webp-convert' on github which tries all methods. The readme-file describes the pros and cons of each method. Its available here: https://github.com/rosell-dk/webp-convert.

    For reasons unknown to me, the imagick/gmagick extensions produces no better quality than the original files. This is only a problem with the extensions, not the exec calls.