PHPackages                             codebuds/webp-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. codebuds/webp-converter

ActiveLibrary[Image &amp; Media](/categories/media)

codebuds/webp-converter
=======================

A service that uses php GD to convert Jpeg, Png, Gif and Bmp into WebP

0.7.0(2y ago)418.4k↓61.3%11MITPHPPHP ^8.3

Since May 9Pushed 2y ago3 watchersCompare

[ Source](https://github.com/codebuds33/webp-converter)[ Packagist](https://packagist.org/packages/codebuds/webp-converter)[ RSS](/packages/codebuds-webp-converter/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (19)Used By (1)

[![Code Coverage Badge](./plugin/.coverage/badge.svg)](./plugin/.coverage/badge.svg)

Webp Converter
==============

[](#webp-converter)

I had already found a great webP conversion package [rosell-dk/webp-convert](https://packagist.org/packages/rosell-dk/webp-convert) that seems to work in many cases.

However, most of my projects will now be running on PHP7.4 and Symfony5, so I created a very small converter for those situations.

Usage
-----

[](#usage)

You can use composer to get this package :

`composer require codebuds/webp-converter`

Then, inside a Symfony controller for example you can use it like the following :

```
use CodeBuds\WebPConverter\WebPConverter;

class PageController extends AbstractController
{
    /**
     * @Route("/", name="home")
     * @return Response
     */
    public function index()
    {
        $path  = "/var/www/symfony/public/images/test.png";
        try {
            $webp = WebPConverter::createWebpImage($path, ['saveFile' => true, 'quality' => 10]);
        } catch(Exception $e) {
            // Do something with the exception
        }
        return $this->render('page/home.html.twig');
    }
```

The `WebPConverter::createWebpImage` static function needs the resource for the image.

This can either just be the path to the image, in which case the function itself will try to create the `Symfony\Component\HttpFoundation\File\File` from the path.

You can also directly pass the File element if you want :

```
public function index()
{
    // ...
    $file  = new File("/var/www/symfony/public/images/test.png");
    $webp = WebPConverter::createWebpImage($file);
    // ...
}
```

Exceptions
----------

[](#exceptions)

Multiple exceptions can be thrown. First the Symfony File is used for the `guessExtension()` function. This allows us to check the type of file provided and will make sure whether the file is called .JPG, .jpeg, .jpg, ... or something else, but it ends up being a jpeg file this is what will be used. If the file is not one of the allowed types (jpeg, png, gif and bmp) an exception will be thrown.

If the provided image is already a webP image the exception will send that information.

If the saveFile or the force options are not booleans, or the quality option is not an integer between 1 and 100 the information will be in an exception.

The filename, filenameSuffix and savePath options need to be strings.

If saveFile is set to true and force to the default false value, and the webP image already exists an exception will be thrown to let the user know force needs to be set to true is you want to override an existing file.

Finally, if the file is one of the allowed types but something goes wrong during the conversion made by GD that exception will be forwarded.

Return values
-------------

[](#return-values)

If no exceptions are present the return will consist of the webP image ressource and what the path would be for the image if you want it saved in the same directory as the original one.

Options
-------

[](#options)

You can also set options but this is not required.

The `saveFile` option is false by default. As mentioned before this will only return the ressource, and the possible path for the webP image. This means you then need to run the gd function to save the image.

However, if you set this function to true the image will be saved automatically by triggering the gd `imagewebp` function.

```
$saveFile = $options['saveFile'] ??= false;
if($saveFile)
{
    imagewebp($imageRessource, $webPPath, $quality);
}
```

If you want to save the file directly there are more options to customize the webP file and it's location :

```
$path = '/var/www/symfony/public/images/a_file.jpg';

WebPConverter::createWebpImage(
    $path,
    [
    'saveFile' => true,
    'force' => true,
    'filename' => 'a_new_file',
    'filenameSuffix' => '_q50',
    'quality' => 50,
    'savePath' => '/var/www/symfony/public/webp'
    ]
);
```

This example will create the webP image /var/www/symfony/public/webp/a\_new\_file\_q50.webp

Default values :

- `saveFile` =&gt; false
- `force` =&gt; false
- `quality` =&gt; 80
- `filename` =&gt; the same as the file that is going to be converted.
- `savePath` =&gt; the same as the path of the file that is going to be converted.
- `filenameSuffix` =&gt; an empty string

As that is possible, the second option is `quality` which by default is 80. This is only useful if the `saveFile` option is set to true (as the image is not created and saved otherwise).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~86 days

Recently: every ~200 days

Total

17

Last Release

859d ago

PHP version history (5 changes)0.1.1PHP ^7.4

0.3.0PHP ^7.4 || ^8.0

0.5.0PHP ^8.0

0.6.0PHP ^8.1

0.7.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/0480f4640e4b77d81842082e7b73e903428b52b68f58e244cdc0108a72939004?d=identicon)[DennisdeBest](/maintainers/DennisdeBest)

![](https://www.gravatar.com/avatar/10d081369f263e74ed4a415f05d3304640e8c777e211f2776340ff0a879f733c?d=identicon)[CodeBuds](/maintainers/CodeBuds)

---

Top Contributors

[![DennisdeBest](https://avatars.githubusercontent.com/u/15683927?v=4)](https://github.com/DennisdeBest "DennisdeBest (67 commits)")[![ThomasMorgana](https://avatars.githubusercontent.com/u/117949247?v=4)](https://github.com/ThomasMorgana "ThomasMorgana (2 commits)")

###  Code Quality

Static AnalysisRector

### Embed Badge

![Health badge](/badges/codebuds-webp-converter/health.svg)

```
[![Health](https://phpackages.com/badges/codebuds-webp-converter/health.svg)](https://phpackages.com/packages/codebuds-webp-converter)
```

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k869.4M8.8k](/packages/symfony-http-kernel)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k251.7M11.6k](/packages/symfony-framework-bundle)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.4k](/packages/symfony-security-bundle)[symfony/security-http

Symfony Security Component - HTTP Integration

1.7k177.2M382](/packages/symfony-security-http)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M339](/packages/api-platform-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
