PHP code example of rkr / image
1. Go to this page and download the library: Download rkr/image 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/ */
rkr / image example snippets
use Kir\Image\Image;
$image = Image::loadFromFile('image.png');
$newImage = $image->getCopy();
$newImage->resizeProportional(500);
$newImage->saveAsWebP('new-image-width-500.webp');
$newImage = $image->getCopy();
$newImage->resizeProportional(null, 500);
$newImage->saveAsWebP('new-image-height-500.webp');
$newImage = $image->getCopy();
$newImage->resizeProportional(500, 500);
$newImage->saveAsWebP('new-image-largest-side-to-500.webp');
use Kir\Image\Image;
$image = Image::loadFromFile('image.png');
$image->resizeProportional(500, 500);
$image->resizeCanvasCentered(500, 500);
$image->saveAsWebP('500x500.webp');
use Kir\Image\Image;
use Kir\Image\Color;
$image = Image::loadFromFile('image.png');
$image->getCopy()
->crop(15 /* Threshold in 0..255 color scale */, 3 /* Border width in % */, Color::whiteOpaque())
->resizeProportional(500, 500)
->resizeCanvasCentered(500, 500)
->saveAsWebP('500x500.webp');