Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Image Driver Vips Laravel Package

intervention/image-driver-vips

A high-performance libvips driver for Intervention Image 3, enabling fast, low-memory image processing for large files. It supports resizing, cropping, format conversion, and more through the familiar Intervention Image API.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install the native dependency first. On Debian/Ubuntu: sudo apt-get install libvips42 libvips-dev, then install the PHP extension (pecl install vips or your distro package) and enable it. Verify with php -m | grep vips and vips --version.
  • Add the packages: composer require intervention/image intervention/image-driver-vips. For Laravel, also install intervention/image-laravel if you want the facade/config integration.
  • Publish the Laravel config if needed: php artisan vendor:publish --provider="Intervention\Image\LaravelServiceProvider". In config/image.php, point the driver at the VIPS driver class, typically \Intervention\Image\Drivers\Vips\Driver::class. Check the package README for the exact class name for your version.
  • First use case: generate a thumbnail from an uploaded image in a controller or job:
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Vips\Driver;

$manager = new ImageManager(new Driver());

$image = $manager->read($request->file('photo')->getRealPath())
    ->cover(400, 400)
    ->toJpeg(82);

Storage::put("avatars/{$user->id}.jpg", (string) $image);
  • Where to look first: the package README for driver class/requirements, the Intervention Image v3 docs for the processing API, your config/image.php, and php -m / vips --version on every environment. The first real win is large upload handling: resize/convert in a queued job instead of doing it inline in the request.

Implementation Patterns

  • Bind a single ImageManager in a service provider and inject it instead of constructing drivers everywhere:
$this->app->singleton(ImageManager::class, function () {
    return new ImageManager(new \Intervention\Image\Drivers\Vips\Driver());
});
  • Keep image work in queued jobs for user uploads, imports, and batch conversions. Pass storage paths and target dimensions into the job, read from a local temp path, process, write back, and delete temp files. Use Bus::batch() for bulk imports and chunk the work so a single job does not exceed queue timeouts.
  • Create a small ImageProcessor service with methods like thumbnail(), hero(), convertToWebp(), and storeVariant(). Controllers should validate and dispatch; the processor should own the Intervention calls. This keeps driver swaps and test fakes contained.
  • For responsive image sets, generate a few variants rather than many: e.g. cover(400, 400) for avatars, scaleDown(width: 1600) for content images, and toWebp(80) for modern output. Store variant metadata (width, height, mime, bytes) alongside the file.
  • Remote disks need care. Many image libraries want a local path. For S3/Spaces, download to a temp file, run VIPS, upload the result, then delete the temp file. Avoid loading the entire remote object into a string unless the image is small.
  • Swap drivers via config, not code. Existing Intervention Image calls generally stay the same; only the manager/driver binding changes. In local development or CI where ext-vips is unavailable, bind GD or Imagick conditionally so the app still boots.
  • Use save($path) for local files and encode() + Storage::put() for Laravel disks. For very large outputs, prefer streaming to a temp file and uploading rather than keeping encoded bytes in memory.
  • Instrument the pipeline: log original dimensions, output dimensions, output bytes, driver name, and duration. VIPS should show lower memory and faster large-image throughput; measure in staging with real phone/camera photos, not tiny fixtures.

Gotchas and Tips

  • The native dependency is the main operational risk. CI, Docker, and production all need libvips and the PHP extension. Pin versions in your Dockerfile and add a deploy health check such as php -r "var_dump(extension_loaded('vips'));" plus vips --version.
  • VIPS is lazy/streaming. Some errors only surface when the image is finally saved or encoded. Wrap the final write in try/catch and clean up partial files so failed jobs do not leave orphaned variants.
  • After changing config/image.php, run php artisan config:clear. Under Octane, restart workers after driver/config changes.
  • JPEG has no alpha. Flatten transparent images onto a background before toJpeg(), otherwise you may get black or unexpected backgrounds.
  • Animated GIF/WebP, AVIF, HEIC, and CMYK JPEG support depends on how libvips was built and the driver’s format handling. Test the exact formats your users upload; do not assume parity with GD/Imagick.
  • EXIF orientation is a common phone-photo bug. Verify orientation with real portrait photos and apply orientation before resizing if needed. Normalize at upload time if your pipeline cannot guarantee it.
  • Remote storage plus temp files is a frequent source of bugs. Use Storage::path() only for local disks; for remote disks use a temp file under storage/app/tmp or tmpfile(), and ensure cleanup in finally.
  • Memory is lower than GD/Imagick but not zero. Large PNG/WebP encodes can still spike. Use scaleDown() before other operations and test with 50MP+ images; set memory_limit based on measured peak, not assumption.
  • Queue workers are the right place for CPU-bound image work. Limit worker concurrency if image jobs saturate CPU, and set job $timeout/$tries based on the largest expected file.
  • Provide a fallback path for local development: e.g. IMAGE_DRIVER=vips|gd and a conditional binding. A missing extension should not take down every request that touches images.
  • Keep driver-specific code out of controllers. Wrap the manager in your own service or decorator so you can swap drivers, add metrics, or fake image processing in tests without rewriting call sites.
  • In tests, use small fixtures and assert dimensions/mime instead of exact bytes. Run at least one CI job with vips installed; keep fast unit tests on a GD/Imagick binding if native setup is painful.
  • Version drift between local libvips and production can change output slightly. Pin OS packages and test a representative image set after upgrades.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager