PHP code example of tihloh / prefab-image
1. Go to this page and download the library: Download tihloh/prefab-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/ */
tihloh / prefab-image example snippets
use Tihloh\Prefab\Image\Image;
Image::open(__DIR__ . '/uploads/photo.jpg')
->autoOrient()
->resize(1200)
->format('webp')
->quality(82)
->save(__DIR__ . '/public/images/photo.webp');
Image::open($source)
->resize(1200, 800)
->save($target);
Image::open($source)
->cover(300, 300)
->format('webp')
->save($target);
Image::open($source)
->thumbnail(300, 300)
->save($target);
Image::open($source)
->crop(100, 50, 500, 300)
->rotate(90)
->flip('horizontal')
->save($target);
Image::open($source)
->autoOrient()
->save($target);
Image::open($source)
->format('webp')
->quality(82)
->save($target);
$image->save(__DIR__ . '/public/photo.webp');
$bytes = $image->encode();
ihloh\Prefab\Image\Image;
Image::open(__DIR__ . '/storage/photo.jpg')
->resize(640)
->format('webp')
->quality(82)
->display();
Image::open($source)
->resize(640)
->format('webp')
->display([
'max_age' => 86400,
]);
$image->display([
'max_age' => 31536000,
'immutable' => true,
]);
$info = Image::inspect($path);
$info->width();
$info->height();
$info->ratio();
$info->mime();
$info->type();
$info->size();
Image::generate(
__DIR__ . '/uploads/photo.jpg',
__DIR__ . '/public/cache/photo-640.webp',
fn (Image $image) => $image
->autoOrient()
->resize(640)
->format('webp')
->quality(82),
);
foreach ([320, 640, 1024, 1600] as $width) {
Image::generate(
$source,
__DIR__ . "/public/images/photo-{$width}.webp",
fn (Image $image) => $image
->autoOrient()
->resize($width)
->format('webp')
->quality(82),
);
}
html
<img src="/image.php" alt="Photo">