trail / images
Image uploads and resizing for trail
0.5.0
2026-11-16 22:05 UTC
Requires
- php: >=8.4
- ext-dom: *
- ext-gd: *
- trail/framework: ^0.5.0
Requires (Dev)
None
Suggests
- trail/storage: `Transform::saveTo()` allows disk writes
Provides
None
Conflicts
None
Replaces
None
README
Image uploads and resizing for trail
install
composer require trail/images
Requires gd. Handles jpeg, png, webp, avif, and gif
use
use Trail\Images\Images;
$image = Images::open($request->file('photo'), maxBytes: 10 * 1_048_576);
$image->fit(2400, 2400);
$image->cover(800, 450, focus: [0.3, 0.6]);
$image->crop(0, 0, 400, 400);
$disk->write('photos/cat.webp', $image->encode('webp', quality: 82));
convert
You can auto resize/convert stuff on upload. It only runs when called so its out of the way. Support webp, avif, jpg, png, gif, or keep. Animated things are left alone because GD cant animated
$avatar = Images::convert($request->file('avatar'), 'webp', quality: 82, cover: [256, 256], maxBytes: 5 * 1_048_576);
$hero = Images::convert($request->file('hero'), 'avif', fit: [2400, 2400]);
$avatar->bytes;
$avatar->type; // webp
$avatar->width;
// needs trail/storage
$url = $avatar->saveTo(Storage::disk('uploads'), 'avatars');
metadata
It strips camera, gps, and editor stuff without changing the actual image/quality/etc. Gif and AVIF just passthrough because animations
$disk->write('photos/cat.jpg', Images::stripMeta($upload->contents()));
svg
use Trail\Images\Svg\Svg;
$clean = Svg::scrub($contents, maxBytes: 100 * 1024);