Download the PHP package zoker/responsive-images without Composer

On this page you can find all versions of the php package zoker/responsive-images. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package responsive-images

Responsive Images for Laravel

Laravel package for automatic image conversion to WebP and responsive sizes generation.

Installation

Configuration

Publish the configuration file:

Driver

Imagick is the default when ext-imagick is loaded; otherwise the package falls back to GD, so a server without the extension keeps working. Set RESPONSIVE_IMAGES_DRIVER to pin one.

imagick (default) gd (fallback)
PHP extension ext-imagick ext-gd
Reads jpg/jpeg, png, webp, gif, avif, bmp, tif/tiff, heic/heif and whatever the ImageMagick build supports jpg/jpeg, png, webp, gif, avif, bmp
Animated GIF animated WebP (every frame is resized for every breakpoint, so slower and heavier) static WebP (first frame only)
Photos faster (≈1.7× on a 4000×3000 JPEG) slower
Memory ≈8 bytes per pixel (Q16), allocated outside PHP; capped by imagick.* (see Memory) ≈5 bytes per pixel, allocated outside PHP by libgd on most distro builds; no cap

Run php artisan responsive-images:clear after switching the driver: generated file names do not depend on it, so the old files would keep being served.

Memory

Both drivers must be planned against the RAM of the server, not against memory_limit. Imagick allocates in ImageMagick, outside the PHP heap. GD is counted in memory_limit only with the libgd bundled into PHP (docker-php-ext-install gd, Herd); Debian/Ubuntu packages (php8.x-gd) are built with --with-external-gd, where the system libgd allocates with malloc and memory_limit does not see it. queue:work --memory counts PHP memory only and does not help either. When the kernel kills the worker, nothing is logged by PHP: the job stays reserved until retry_after, is picked up again with attempts above tries and fails as MaxAttemptsExceededException without a cause. Look in journalctl -k | grep -i oom.

generate() decodes the original once, reduces it to the target size once and cuts every breakpoint from that base, so with a target width the peak is about one decoded copy of the original (two for a moment while its full-size WebP is encoded) plus the small base:

Original Pixels Imagick (8 B/px) GD (5 B/px)
4000×3000 12 Mpx ≈ 96 MB ≈ 60 MB
4000×4000 16 Mpx ≈ 128 MB ≈ 80 MB
8000×4500 36 Mpx ≈ 288 MB ≈ 180 MB

Without a target width (make('a.png') with no dimensions) the base is the original itself, so the peak stays around two copies. What keeps such a job alive is the Imagick resource limits, applied with Imagick::setResourceLimit() when the driver is imagick, once per process (queue worker and php-fpm alike):

Above memory ImageMagick moves the pixel cache to memory-mapped files, above map to plain disk files: slower, but the worker survives. Generation happens once per image and size set, so that slow pass is a one-off. Values are bytes or a size with a K/M/G suffix; null leaves ImageMagick's own default. These are upper bounds: a lower value in the server's policy.xml wins. The defaults are conservative on purpose, since the package is also installed on small VPSes; raise them on servers with more RAM. GD has no such switch: on a GD host the server's RAM is the only limit, so keep uploads reasonably sized.

queue => false or a sync queue connection moves all of this into php-fpm: on a small server a large original will then kill the web request, not a worker. Keep an asynchronous queue on such hosts.

Supported Formats

Only files whose extension is listed in extensions are converted (comparison is case-insensitive, so PHOTO.JPG counts as jpg):

A listed extension is converted only if the driver on this server can read it: GD is checked with imagetypes() (AVIF needs GD built with libavif), Imagick with Imagick::queryFormats() (HEIC needs ImageMagick built with libheif). With gd, tif/tiff/heic/heif are therefore served as-is.

Never add vector or document formats (svg, pdf, ps, eps) when using Imagick: ImageMagick hands them to external delegates, which is a known attack surface. SVG is best served as-is anyway.

Animated GIF with the gd driver becomes a static WebP. Use imagick, or remove gif from extensions.

Formats browsers cannot display (tif/tiff, heic/heif). Before the job has run, the untouched original would be useless as a fallback, so the first make() converts the full-size WebP synchronously (one conversion; the breakpoint sizes are still built by the job). If that conversion fails, the error is reported and the original URL is returned.

Any other file (svg, ...) is served as-is:

A <source type="image/webp"> is rendered only once generated images in the output format exist. Until the job has finished, the original (or its WebP copy) is rendered as a plain <img>.

Usage

Facade

Blade Component

Blade Directive

Working with the ResponsiveImage Object

ResponsiveImages::make() returns a ResponsiveImage object with the following methods:

Available public properties:

Property Type Description
$src string URL of the largest generated image (or the original / fallback)
$generatedImages array All generated images as [width => url]
$srcset string The srcset attribute value (same as getSrcset(); handy where methods cannot be called, e.g. sandboxed Twig)
$sizes string The default sizes attribute value (100vw)
$width int Target width (0 for unsupported files)
$height int Target height (0 for unsupported files)
$format string Output format (e.g. webp), or the source extension for unsupported files / fallback

Artisan Commands

Clear Generated Images

Note: Images are automatically regenerated when the original file changes or config parameters are updated. No manual regeneration needed!

Dimensions

width and height of the result (and of the rendered <img>) are the same whether make() builds it from freshly generated files or from files already on the output disk:

Arguments Target size Generated widths
width and height as passed, the original is not read breakpoints ≤ width, plus width
width only height = width × original ratio breakpoints ≤ width, plus width
height only width = original width, height as passed breakpoints ≤ original width, plus it
none original width and height breakpoints ≤ original width, plus it

When the original has to be consulted, only its header is read (getimagesize(), no decoding). A JPEG/TIFF with an EXIF orientation of 5–8 is auto-rotated on conversion, so its width and height are swapped here too. If the header cannot be read (e.g. HEIC, which getimagesize() does not understand, or a corrupt file), the result carries the passed values (0 when omitted) and the missing sizes are requested on every cache refresh, as before.

Cache

The result of make() is cached with Cache::flexible() in cache_store; cache_ttl is [stale, expire] in seconds, [86400, 604800] by default. A cache hit touches neither disk nor image. The entry is recomputed in the background after stale, and synchronously after expire. It only changes when the original file, breakpoints, quality or format change, so after replacing an image under the same name run php artisan responsive-images:clear (or lower the TTL).

Paths

A leading / in the source path is ignored: make('/uploads/a.jpg') is the same image, cache entry and job as make('uploads/a.jpg'). make('/') and make('') return null, and responsive-images:clear / clears everything.

How It Works

  1. Package accepts image path, optional target width and height (uses original dimensions if not specified), Alt attribute, optional disk (uses default disk if not specified)
  2. Automatically calculates responsive sizes based on breakpoints from config
  3. Converts image to WebP
  4. Generates versions for each size with hash-based filenames
  5. Caches results using hash of (file modification time + dimensions + quality + format)
  6. Automatically invalidates cache when original file or parameters change
  7. Returns HTML with <picture> and srcset

Queue

Missing sizes are built by the GenerateResponsiveImages job, and until it has run make() returns the fallback. Generation happens inside the make() call instead, and the first call already returns every size, when:

If that in-request generation fails, the error is reported and the fallback is returned, so the page still renders. Decoding then happens inside the web request: see the memory note under Configuration before enabling this on a small server.


All versions of responsive-images with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/laravel-package-tools Version ^1.93
intervention/image Version ^3.0|^4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zoker/responsive-images contains the following files

Loading the files please wait ...