1. Go to this page and download the library: Download shykat199/webpbolt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Shykat\WebpBolt\ImageProcessor;
use Shykat\WebpBolt\Transforms\Resize;
$processor = (new ImageProcessor())
->addTransform(new Resize(1600, 1600));
$result = (new BatchProcessor($processor))
->source('public/uploads')
->destination('public/webp')
->run(new WebpEncoder(quality: 78));
(new BatchProcessor())->source('public/uploads')->run();
// public/uploads/2024/cat.jpg
// public/uploads/2024/cat.webp <- new
$result = (new BatchProcessor())->source('public/uploads')->run();
foreach ($result->failed as $path => $error) {
fwrite(STDERR, "FAILED {$path}: {$error}\n");
}
(new BatchProcessor())
->source('public/uploads')
->skipExisting(false)
->run(new WebpEncoder(quality: 65));
$result->converted; // int — files successfully written
$result->skipped; // int — up to date, or output was larger
$result->failed; // array — [source path => error message]
$result->bytesIn; // int — total original size
$result->bytesOut; // int — total new size
$result->bytesSaved(); // int
$result->percentSaved(); // float
$result->seconds; // float
$result->total(); // int — every file looked at
$result->summary(); // string — the one-line report
use Shykat\WebpBolt\ImageProcessor;
use Shykat\WebpBolt\Encoders\WebpEncoder;
use Shykat\WebpBolt\Transforms\Resize;
use Shykat\WebpBolt\Transforms\Grayscale;
$path = (new ImageProcessor())
->addTransform(new Resize(800, 800))
->addTransform(new Grayscale())
->save('photo.jpg', 'output/photo.webp', new WebpEncoder(quality: 75));
use Shykat\WebpBolt\WebpBolt;
WebpBolt::make('photo.jpg')->watermarkText('(c) 2026 Studio')->save();
use Shykat\WebpBolt\Transforms\Watermark;
use Shykat\WebpBolt\Enums\Position;
Watermark::text('(c) 2026 Studio')
->font(__DIR__ . '/fonts/Inter.ttf', 28)
->color('#ffffff')
->position(Position::BottomLeft)
->opacity(70)
->margin(30);
$processor = (new ImageProcessor())
->addTransform(new Resize(1600, 1600))
->addTransform(Watermark::image('logo.png')->opacity(45));
(new BatchProcessor($processor))
->source('public/uploads')
->destination('public/webp')
->run(new WebpEncoder(80));
namespace Shykat\WebpBolt\Transforms;
use GdImage;
use Shykat\WebpBolt\Contracts\TransformInterface;
class Watermark implements TransformInterface
{
public function __construct(private string $text) {}
public function apply(GdImage $image): GdImage
{
$color = imagecolorallocatealpha($image, 255, 255, 255, 50);
imagestring($image, 5, 10, 10, $this->text, $color);
return $image;
}
}
namespace Shykat\WebpBolt\Encoders;
use GdImage;
use Shykat\WebpBolt\Contracts\EncoderInterface;
class AvifEncoder implements EncoderInterface
{
public function __construct(private int $quality = 60) {}
public function encode(GdImage $image, string $destinationPath): bool
{
imagepalettetotruecolor($image);
imagealphablending($image, false);
imagesavealpha($image, true);
return imageavif($image, $destinationPath, $this->quality);
}
public function extension(): string
{
return 'avif';
}
}
(new BatchProcessor())->source('public/uploads')->run(new AvifEncoder(60));
use Shykat\WebpBolt\Exceptions\ImageNotFoundException;
use Shykat\WebpBolt\Exceptions\ImageTooLargeException;
use Shykat\WebpBolt\Exceptions\UnsupportedFormatException;
use Shykat\WebpBolt\Exceptions\EncodingFailedException;
try {
WebpBolt::make($path)->resize(1600)->save();
} catch (UnsupportedFormatException $e) {
// not an image we can read
} catch (ImageTooLargeException $e) {
// would blow the memory limit
}