rokka/imagine-vips
Libvips adapter for Imagine, offering fast, multi-threaded image processing with low memory use. Works via PHP FFI (recommended) or php-vips-ext, plus php-vips classes. Supports common Imagine operations like open, thumbnail, and save; vips 8.7+ recommended.
Installation:
composer require rokka/imagine-vips
Ensure either:
php-vips-ext ≥1.0.8 (manual install) ANDphp-vips (auto-installed via Composer).Verify libvips:
use Imagine\Vips\Imagine;
$imagine = new Imagine();
if ($imagine->isSupported()) {
echo "libvips is ready!";
}
$imagine = new Imagine();
$image = $imagine->open('large-image.jpg')
->thumbnail(new \Imagine\Image\Box(200, 200))
->save('thumbnail.jpg');
Image Manipulation:
$image = $imagine->open('input.jpg')
->resize(new \Imagine\Image\Box(800, 600))
->rotate(90) // Only 90° increments work with libvips <8.6
->crop(new \Imagine\Image\Box(400, 300), new \Imagine\Image\Point(100, 100))
->save('output.jpg');
Layer/Animation Support (vips ≥8.7):
$layers = $imagine->open('animated.gif')->layers();
$layers->setDelay(0, 500); // Set delay for frame 0 to 500ms
$layers->save('output.gif');
Format-Specific Options:
$image->save('output.webp', [
'webp_reduction_effort' => 6, // Max quality (0-6)
'quality' => 90,
]);
convertToAlternative() for unsupported operations:
$image->convertToAlternative(new \Imagine\Gd\Imagine())->save('fallback.jpg');
$image->stripProfiles()->save('clean.jpg');
Version Dependencies:
paste() and arbitrary-angle rotation.magicksave (fallback to Imagick/GD if missing).php-vips-ext (better performance/maintenance).BC Breaks:
autorotate/n defaults now apply during open().Drawer::text() behavior changed (use textWithHeight() for legacy).\Imagine\Vips\Layers requires explicit return types.Unsupported Features:
fill(), histogram, colorize missing (fallback to Imagick/GD).echo \Jcupitt\Vips\Config::version(); // e.g., "8.12.2"
vips_cache_set_max_mem in constructor:
$imagine = new Imagine(['vips_cache_set_max_mem' => 1024 * 1024 * 1024]); // 1GB
try {
$image->save('output.heic');
} catch (\Imagine\Exception\NotSupportedException $e) {
$image->convertToAlternative()->save('output.jpg');
}
$image->save('output.jpg', [
'jp2_quality' => 95, // JPEG2000 (if supported)
'force_magick' => true, // Force magicksave (vips ≥8.7)
]);
$imagine = new Imagine([
'default_options' => [
'quality' => 85,
'png_quality' => 100, // Disable pngquant
],
]);
\Imagine\Vips\Drawer for shapes/colors.fill()/histogram in \Imagine\Vips\Image.How can I help you explore Laravel packages today?