Search code examples
phpwebp

How to enable Webp support as true on php 7.4.10 version?


I'm working with php 7.4.10 version on Red Hat Linux 86_64 server and i would like to convert all images automatically to webp extension after user upload an image. I have php code that works fine to upload image, but when i try to upload an image i get the error below:

Fatal error: Uncaught Error: Call to undefined function imagewebp() in....

When i got that error above, i typed var_dump (gd_info()) on page and after this i got these informations below:

array(14) { 

["GD Version"]=> string(26) "bundled (2.1.0 compatible)" 
["FreeType Support"]=> bool(true) 
["FreeType Linkage"]=> string(13) "with freetype" 
["GIF Read Support"]=> bool(true) 
["GIF Create Support"]=> bool(true) 
["JPEG Support"]=> bool(true) 
["PNG Support"]=> bool(true) 
["WBMP Support"]=> bool(true) 
["XPM Support"]=> bool(true) 
["XBM Support"]=> bool(true) 
["WebP Support"]=> bool(false) 
["BMP Support"]=> bool(true) 
["TGA Read Support"]=> bool(true) 
["JIS-mapped Japanese Font Support"]=> bool(false) 

}

Based on array result above, the Webp support is checked as false:

["WebP Support"]=> bool(false)

In this case how could i enable WebP Support as ["WebP Support"]=> bool(true)? I found some similar questions related to my doubt:

  1. Update GD version to support Webp for PHP 7.3
  2. How to compile php to enable webp support?
  3. Enabling WebP Support in GD Library on Ubuntu 18.04 running on LiteSpeed

but unfortunatly i didn't find a correct way to enable webp support on my server.


Solution

  • On a fresh php installation, adding gd with sudo apt install php7.4-gd enables webp automatically. Output in phpinfo(); is:

    gd
    GD Support  enabled
    GD headers Version  2.3.0
    GD library Version  2.3.0
    FreeType Support    enabled
    FreeType Linkage    with freetype
    GIF Read Support    enabled
    GIF Create Support  enabled
    JPEG Support    enabled
    PNG Support     enabled
    WBMP Support    enabled
    XPM Support     enabled
    XBM Support     enabled
    WebP Support    enabled
    BMP Support     enabled
    TGA Read Support    enabled