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

Laravel Image Laravel Package

folklore/laravel-image

A Laravel image package that simplifies common image workflows with a clean API for resizing, cropping, and generating thumbnails while integrating with Laravel’s filesystem and configuration. Useful for handling uploaded images and model attachments in apps.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Treat this as an early alpha, not a drop-in upgrade. Confirm PHP 8.3+, Laravel 12+, and that laravel-mediatheque 2 has an installable alpha before planning adoption; this release requires ^2.0@alpha and resolves media ids through that package’s media resolver.
  • Install both alpha constraints, then publish config/image.php. Only override the keys you need: presets, url.host, url.prefix, signing.*, strict, limits, delivery, upscale.
  • Run php artisan image:doctor before writing application code. It checks the renderer driver and formats, FFI/libvips, disk read/write/delete, lock store, signing key, route behavior, session cookies, and URL host. Use --write only against a safe derivatives disk.
  • Read the getting-started, presets, URLs/signatures, and CDN guides first. They map directly to the day-to-day workflow: define presets, build URLs, deliver through a route or CDN.
  • First use case: render a preset from a disk-backed image with Image::for($path)->preset('thumb')->url(). For private sources, use signed(expires: ...); unsigned URLs are not an option.
  • Decide delivery early: opt into Route::image($prefix) or Image::routes() for canonical v2 paths, or serve versioned URLs through a CDN and let DiskStore redirect to a public disk URL.
  • If migrating from 1.x, wait for the beta compatibility layer unless you are prepared to rewrite URLs and server-side URL generation. The 2.x API is new, Imagine is gone, and the 1.x API is only promised for beta.

Implementation Patterns

  • Use the immutable PendingImage builder as the single URL/spec composition point: preset(), width(), height(), size(), fit(), ratio(), format(), quality(), signed(), host(), then url(), variant(), variants(), or render(). Keep this in controllers, API resources, and Blade view models rather than constructing URLs by hand.
  • For responsive images, define versioned presets and use variants() to get the preset’s responsive widths × formats with exact dimensions from source metadata. Feed those into srcset/picture, and use ImageVariantResource ({preset, url, width, height, mime}) for JSON APIs so clients do not need image dimensions.
  • Version presets deliberately. Versioned URLs get Cache-Control: public, max-age=31536000, immutable; changing widths, formats, or rendering behavior without bumping the preset version leaves stale CDN and browser caches in place.
  • Register resolvers centrally from config or with Image::resolver(). Use the disk resolver with an optional root for any Laravel disk. Use Image::useHost() when URLs must vary per request, tenant, or CDN hostname.
  • Treat private sources as signed-only. In strict mode, a free-form spec only receives a signed URL, while presets are served at their current version and widths. Check limits at URL-build time so invalid specs fail in the application, not during rendering.
  • Choose delivery per environment: the route serves canonical v2 paths, validates signatures and expiry, enforces limits, renders derivatives once under a lock, then streams or redirects. For CDN-first setups, keep URL generation server-side and use long-lived versioned URLs for public images; use expiring signed URLs for private images.
  • Make the lock store shared in multi-node deployments. Render locks are per derivative and protect against duplicate work; a process that waits too long returns 503 with Retry-After. Use Redis or another atomic shared store for production route rendering.
  • Test with Image::fake(), which works through the builder and keeps derivatives in memory via InMemoryDerivativeStore. Use it for URL/spec and controller tests, but keep at least one integration test against the real resolver, renderer, store, and route.
  • When extending the package, implement the public contracts (ImageSpec, UrlCodec, Signer, SourceResolver, ImageSource, Renderer, Operation, DerivativeStore, ImageVariant) and use the provided contract test traits. This is the intended path for custom storage, signing, or rendering engines.
  • Expect the default InterventionRenderer to use the auto driver order: libvips, then Imagick, then GD. Pin image.renderer.driver where output must be reproducible across environments, especially for AVIF, HEIC, color profiles, and EXIF handling.
  • Use DiskStore for derivatives on any Laravel disk under image.derivatives.path; configure public-disk redirects deliberately. For S3-compatible disks, versioning derives from mtime or ETag and is cached for version_ttl, so source changes can take up to that TTL to appear as new versions.

Gotchas and Tips

  • This is 2.0.0-alpha.1: APIs, config keys, and contracts can change before stable. Do not ship it as the only image path in a production application without a rollback plan.
  • The required laravel-mediatheque 2 alpha may not be available at the same time as this release. Verify dependency resolution before estimating migration work.
  • There is no JavaScript package in 2.x. Any client-side URL building, signing, or preset logic from 1.x must move to the server. Signed URLs must be generated by Laravel.
  • The 1.x API is removed in this alpha; the compatibility layer is planned for beta. 1.x URLs continue to decode, but existing application code calling the old API will break.
  • strict mode changes behavior: free-form specs get signed URLs, presets are served at current versions and widths, and limits are enforced at URL construction. Audit generated URLs and tests under both strict and non-strict settings.
  • Private sources only receive expiring signed URLs. Do not cache those responses publicly; the package sets private for private sources and clips max-age to the URL’s remaining lifetime, but your own proxies and CDN rules must respect it.
  • Signing keys derive from APP_KEY and APP_PREVIOUS_KEYS by default. Plan key rotation with previous keys configured, or old URLs will fail signature checks. Rebuild config caches after key changes.
  • The opt-in image route runs with the project’s middleware. If that middleware starts sessions or sets cookies, CDN caching and image:doctor’s route check will flag it. Keep the route on a minimal middleware stack, or serve through the CDN and public disk redirects instead.
  • The route only serves canonical v2 paths. Hand-built or legacy-shaped URLs will not be served by it even if signatures are valid.
  • Caching headers are not a substitute for versioning. Immutable caching applies to versioned URLs; expiring URLs are capped by remaining lifetime; private sources are private. Changing a source file behind the same version will not invalidate browser or CDN caches.
  • DiskStore redirects to the disk URL only when the disk is public. On private disks it must stream, which changes CDN behavior and offload characteristics.
  • Render locks are only as good as the lock store. File or array stores are not sufficient across containers. Watch for 503/Retry-After under load and size PHP timeouts, memory, and lock wait limits accordingly.
  • Rendering is opinionated: derivatives are upright from EXIF, converted to sRGB where supported, metadata-stripped, and never upscaled by default. HEIC requires Imagick/libheif or libvips; GD will not cover all formats. Verify the actual driver with image:doctor, not assumptions.
  • intervention/image must be at least 4.3.4. The renderer applies the spec’s or source’s transform, writes JPEG, PNG, GIF, WebP, and AVIF with per-format image.quality, and raises image.memory_limit during rendering. Large source images can still exhaust memory; set limits and test representative files.
  • image:doctor --write writes, reads, and deletes a file on the derivatives disk. Do not point it at an unrelated production disk or a path with meaningful contents.
  • Image::fake() is not an end-to-end test. It does not exercise the real route, signing expiry, CDN headers, lock contention, or disk driver behavior. Keep a real integration test for the disk resolver, renderer, store, and route.
  • Config publishing is partial by design, but cached config is still all-or-nothing. Re-run config:cache after changing presets, hosts, prefixes, signing settings, limits, or delivery mode.
  • The disk resolver keeps path containment and caches source dimensions, mime type, EXIF orientation, and version. If dimensions or orientation look stale after replacing a file, check version_ttl and the disk’s ETag/mtime behavior before debugging the renderer.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource