Skip to content

berry.utils.ImageHelper

Nikos Siatras edited this page Jan 6, 2024 · 5 revisions

ImageHelper.ConvertImageToWebP

Description

public function ConvertImageToWebP(string $source, int $quality = 100, bool $removeOld = false): string

This function converts .jpg, .png and .gif format images into .webp

Parameters

  • $source is the the source image path to convert
  • $quality ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file)
  • $removeOld set to true if you want to delete the original file

Example

The following example converts a .png file to .webp

require_once(__DIR__ . "/berry/utils.php"); // Include berry utils package

$imageHelper = new ImageHelper();
$originalImagePath = "myPhoto.png";
$newWebPPath = $imageHelper->ConvertImageToWebP($originalImagePath,80,false);

print $newWebPPath;