nwtn/php-respimg
nwtn/php-respimg is a PHP library for responsive image handling: generate resized image variants, build srcset and sizes markup, and serve appropriately sized images across devices with simple configuration for PHP applications.
Architecture fit. nwtn/php-respimg is a batch/build-time responsive-image workflow, not a request-time transform service. It fits a Laravel app that accepts or curates source images, generates a known set of derivative widths, caches them on disk or object storage, and renders srcset/sizes markup. It is a direct lever for a Core Web Vitals/image-weight backlog on content, catalog, and marketing surfaces. It is a poor fit for dynamic URL-parameterized resizing, edge/CDN-on-the-fly format negotiation, read-only/serverless runtimes without a custom worker image, or products that need arbitrary per-request sizes. Treat it as a small orchestration layer over native image tooling (ImageMagick plus optimizers, potentially a Node CLI); the real platform dependency is the binary/toolchain, not the Composer package.
Integration feasibility. composer require is trivial; the integration cost is everything around it: baking ImageMagick/GraphicsMagick and format optimizers into a dedicated worker image, owning derivative storage layout and cache invalidation, and validating the shell-out boundary. Sources indicate likely Laravel 5.x-era wiring and PHP 5.6/7.x idioms; PHP 8 and Laravel 10/11 compatibility must be proven in a spike, not assumed. Because filenames and paths cross into a subprocess, path-escape and command-injection review are mandatory. Error handling is likely coarse (exit code only), so partial writes and silent no-ops must be detected by our code.
Technical risk. Maintainer risk is high: zero stars/score signal here, zero tracked dependents, single-author pattern, and no visible release cadence. Plan for a vendor-or-fork decision, not a supported dependency. Transitive risk is high because the Node/ImageMagick/optimizer toolchain is a separate upgrade track we inherit but do not control. Runtime risk is medium: CPU/RSS spikes on large PNGs or multi-page inputs, and temp-file concurrency behavior is unknown. Correctness risk is medium: no manifest/idempotency means re-runs can duplicate or orphan derivatives, and cache invalidation is ours to design. Licensing risk is low but must be confirmed before vendoring.
Key questions for a 2–3 day spike.
TPM leverage. Use this package as a build-baseline against paid image services: it shows what we get from self-hosted generation before paying per-transformation. If the roadmap requires on-the-fly transforms or AVIF/WebP negotiation at request time, skip it and evaluate imgproxy, Cloudinary, or imgix. If the need is stable breakpoints and cached derivatives, this can be a cheap performance win only behind an internal abstraction and an explicit “we own this forever” maintenance note.
Stack fit. Fits Laravel + queue workers + local/S3 disk + a Blade srcset/sizes component. Does not fit Lambda/Fargate without a custom Node+ImageMagick image, read-only containers, non-PHP stacks, or teams unwilling to own native/Node runtimes in the deploy artifact.
Migration path. Do not call the package directly from controllers, models, or Blade. Define an internal contract such as ImageTransformer::transform(source, widths, formats): DerivativeSet and implement it once with this package. Own derivative naming, manifest, and storage layout in our application, not in package defaults, so cached URLs survive a backend swap. That adapter is the entire risk-mitigation strategy: it gives a one-file replacement path to spatie/laravel-medialibrary, intervention/image v3, spatie/image-optimizer, or an HTTP call to a managed transform service.
Compatibility. Pin the exact package version and PHP constraint. Add it to the dependency-review allowlist with an explicit “unmaintained, internally owned” annotation. Verify Composer auto-discovery and Laravel service-provider wiring on our target version. If PHP 8 or Laravel 10/11 breaks it, prefer a small vendored fork over a compatibility shim; if the fork exceeds roughly two engineer-days, switch backends instead. Confirm the license before including it in the repo.
Sequencing.
ImageTransformer interface and a no-op/stub implementation; wire the Blade srcset helper so front-end work is not blocked.Maintenance. Treat this as in-house code from day one. Assign a named owner in the service catalog. Realistic steady-state cost is a handful of hours per quarter plus a fork-and-patch event when PHP or the base image moves. Track two upgrade streams: the frozen PHP package and the Node/ImageMagick/npm/OS image CVEs. Include both in dependency scanning.
Support. There is no vendor, no community, and no external escalation path. On-call runbooks must be written by us. First triage step for missing derivatives should be: confirm node, convert, and format optimizers exist in the worker image that actually built the job.
Scaling. Cost scales with CPU-seconds and bytes, both horizontally through queue workers. Size the worker pool from the spike’s measured images/sec/worker, and set concurrency below the point where RSS × workers approaches the container limit. Never execute transforms in the web request path: a synchronous transform converts image size directly into p99 latency and thread starvation. At high enough volume, migrate to a dedicated media service rather than growing a PHP-orchestrated batch process without bound.
Failure modes to instrument.
node/convert/optimizer in a freshly built image → silent failure to generate derivatives.srcset on mobile; alert on derivative-completeness ratio, not just job success.Ramp-up. A PHP developer can call the API in under a day. Platform/ops needs roughly 2–4 days for worker image, queue, storage lifecycle, and dashboards. Realistic total to production-grade is about one engineer-week, excluding art-direction work and excluding the fallback rewrite if the spike fails.
Recommendation. Adopt only behind the adapter contract, only after the spike passes on our exact runtime, and only with an accepted “we own this forever” maintenance note. If the spike shows PHP 8/Laravel incompatibility, or if the roadmap needs on-the-fly transforms, skip it and use a maintained PHP media library for offline derivatives or a managed/imgproxy service — either is cheaper than maintaining a Node runtime in the request path for a package with zero dependents.
How can I help you explore Laravel packages today?