Download the PHP package onlinedigital/laravel-perfect-image without Composer

On this page you can find all versions of the php package onlinedigital/laravel-perfect-image. 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 laravel-perfect-image

Laravel Perfect Image

Automatic responsive image optimization for Laravel. Detects rendered image dimensions, caches the most common resolutions, and generates srcset attributes automatically.

Features

Installation

Add Middleware (Optional - for automatic JS injection)

Add to your bootstrap/app.php:

Or apply to specific routes:

Publish Config

Config Options

Usage

Basic Usage

In your Blade templates:

Example:

This generates:

sizes is learned from how the rendered width changes with the viewport width (100vw until something has been learned).

Custom Sizes

The third argument is a list of widths that overrides the learned resolutions:

The directive accepts the same arguments:

JavaScript

While collect_dimensions is enabled, the JavaScript is injected automatically (before </body>) on pages that contain tracked images. It does not need jQuery.

Creating Custom Drivers

Create a class that implements OnlineDigital\PerfectImage\Contracts\Driver:

Register it in a service provider:

How It Works

  1. First Visit: If collection is enabled and no resolutions are cached for an image, the Blade directive adds src, data attributes and an onload handler
  2. JavaScript Tracking: On page load and whenever an image or the window is resized (throttled, with a trailing call), JS measures every tracked image
  3. Dimension Collection: Once enough samples were gathered, all images are sent in a single batch to the _perfect_image_observer endpoint
  4. Caching: The server saves the most common resolutions (at most max_resolutions) and a sizes value
  5. Applying: The response contains src, srcset and sizes, which JS applies without reloading the page
  6. Subsequent Visits: srcset is generated from cached resolutions

Collecting all resolutions automatically (Playwright)

Instead of waiting for someone to resize a browser window, a script can open the pages, sweep the viewport from the smallest phone (320px) to a 2K desktop (2560px) and trigger the collection. This is also the workflow meant for coding agents: after adding a page or a component, run the collector for those URLs and commit the result.

Setup (once)

Set the JSON file store (PERFECT_IMAGE_CACHE_DRIVER=storage_file). Collected data is written to resources/perfect-image.json, so it can be committed and deployed with the code.

Run

The application must be running (for example php artisan serve) on the same machine/filesystem.

What the command does:

  1. Turns the collection on with a temporary flag file (storage/app/perfect_image_collect.flag). The flag is ignored in production, so there is no per request cost there. It is removed afterwards, and the previous state is restored even if the command is interrupted.
  2. Runs scripts/collect.mjs with Playwright. For every page it loads the page, forces lazy images to load, resizes the viewport step by step (and exactly at the usual breakpoints) and measures every tracked image.
  3. Calls the collect API once per page and prints a JSON report (--json for JSON only).

Useful options:

Option Default
--base-url app.url Running application
--max-per-template 3 Discovered pages visited per route (/product/{slug}) or URL directory
--all Visit every discovered URL
--min-width, --max-width, --step 320, 2560, 40 Viewport sweep
--concurrency 2 Pages in parallel (1 with --fresh)
--header="Name: value" Extra request headers
--storage-state=file.json Playwright storage state for pages behind a login

Notes:

Without artisan

The script can be used directly (collection must already be enabled, see collect_dimensions):

Exit codes: 0 ok, 1 errors, 2 nothing measured or images left unmeasured, 3 collection disabled.

Coding agents

See AGENTS.md for the short workflow to give to an agent.

Route

The package automatically registers the observer route:

Request body (resolutions items are [width, height] or [width, height, viewportWidth]):

Several images can be sent at once (this is what the JavaScript does):

Responses: 200 with the resulting src/srcset/sizes per image id, 422 for an invalid payload, 403 (collect_dimensions_disabled) when collect_dimensions is off.

License

MIT


All versions of laravel-perfect-image with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^10.0|^11.0|^12.0|^13.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 onlinedigital/laravel-perfect-image contains the following files

Loading the files please wait ...