Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nishantshah977/compress-to-webp

Compress your jpg, jpeg, png and convert into webp without losing quality ( depends upon level )in PHP.
https://github.com/nishantshah977/compress-to-webp

compression image-processing seo web-optimization webp

Last synced: 6 days ago
JSON representation

Compress your jpg, jpeg, png and convert into webp without losing quality ( depends upon level )in PHP.

Awesome Lists containing this project

README

        

# compress-to-webp
Compress your jpg, jpeg, png and convert into webp without losing quality ( depends upon level )in PHP.

* **Cup.jpg** is original
* **test/filename_to_convert.webp** is compressed

```
$dir,
'file_type' => array(
'image/jpeg',
'image/png',
'image/gif'
)
);

$ImgCompressor = new ImgCompressor($setting);
$jw = new ImageToWebp();

/* Arguments: 'cup.jpg' - Original image path, 'jpg' - Output format, 5 - Compression level (0-9)
*/

$result = $ImgCompressor->run('cup.jpg', 'jpg', 5);

if ($result['status'] === 'success') {
$compressedImageName = $result['data']['compressed']['name'];

/*
Arguments: Compressed image path, Output WebP image path, Quality level (95 in this case)
*/
$jw->convert($dir . '/' . $compressedImageName, $dir.'/'.$file,95);
unlink($dir.'/'.$compressedImageName);
echo "Done";
} else {
echo 'Error: ' . $result['message'];
}

?>
```

# Thanks to
1. [PHP-Image-Compressor-Class](https://github.com/bachors/PHP-Image-Compressor-Class)
2. [PHP-ImageToWebp](https://github.com/rakibtg/PHP-ImageToWebp)

**Stay tuned for full readme.md** or take reference from `index.php` comment