Download the PHP package johannschopplich/kirby-blurry-placeholder without Composer

On this page you can find all versions of the php package johannschopplich/kirby-blurry-placeholder. 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 kirby-blurry-placeholder

[!NOTE] This plugin is not actively maintained anymore. I recommend to use Kirby ThumbHash in combination with unlazy (an evolved Loadeer.js) for a similar effect. It's the successor of this plugin and provides a more modern and flexible approach to lazy loading images.

Thank you for your support and feedback over the years, especially since it was my first plugin for Kirby!

Example of ThumHash and unlazy Inline a thumbnail of your image: Lazy load all images with the `loading="lazy"` attribute:

Kirby Blurry Placeholder

This plugin implements progressive image loading, providing a better user experience. Tiny thumbnails which inherit the aspect ratio of their source image are combined with a blurry effect for a better placeholder than solid colors, without sacrificing payload.

How it works:

  1. An inline, URI-encoded SVG fills the src attribute of a given image element. The blurred image is wrapped in an SVG to avoid rasterizing the filter.
  2. The large images are then only requested when they are within the viewport.

Key Features

Requirements

Installation

Download

Download and copy this repository to /site/plugins/kirby-blurry-placeholder.

Git Submodule

Composer

Usage

As Kirby Image Block

Each Kirby website is tailored to its own unique use case. Thus, this plugin won't add a Kirby block by default. Instead, take a look at the provided image block example to get an idea of how to implement blurry placeholders within blocks.

Of course, you can just copy the block into your site/snippets/blocks folder of your current Kirby project, use it as is, or adapt it to your needs!

As File Method

$file->placeholderUri() creates and returns the URI-encoded SVG placeholder.

As KirbyTag

This plugin provides a (blurryimage: …) KirbyTag built upon Kirby's core (image: …) tag. All of Kirby's image tag options are inferred and thus available for the custom tag as well.

The (blurryimage: …) tag:

Example use within a KirbyText field:

If you have enabled srcset's in the options, the KirbyTag syntax stays the same. Just the output changes.

Lazy Loading in the Frontend

To lazily load the images once they become visible in the viewport, a JavaScript library is necessary. 🦌 Loadeer.js is written with this Kirby plugin in mind. In a nutshell, it's a tiny, performant, SEO-friendly lazy loading library and can be used with or without a build step if you don't have a frontend asset build chain.

Without Build Step & Auto Initialization

Simply load it from a CDN:

Import As ES Module

You can use the ES module build by installing the loadeer npm package:

Automatically Calculate the sizes Attribute

Loadeer.js supports setting the sizes attribute automatically, corresponding to the current size of your image. For this to work, the data-sizes attribute has to be set to auto. If you have srcset's enabled in your configuration, this is already done for you when using the (blurryimage: …) KirbyTag.

Use a Lazy Loader of Your Choice

Each parsed KirbyTag adds the data-lazyload attribute to the img element. Consequently, you can let a lazy loader of choice select these elements by passing [data-lazyload] as a selector.

Animating the Blur

🎨 Animating with the "Blur Down" Technique > ⚠️ **Disclaimer**: Please avoid copying any code until reading this section. This is an experimental technique that comes with caveats (mostly performance issues). When using Loadeer.js, we can target all lazy-loaded images with `[data-lazyload]` and refine this selection with `[data-src]` only to target the images that haven't been fully loaded yet. We can then apply a transition to such properties. As we are manually blurring the `img` **element**, whose `src` attribute is our generated SVG (so essentially the SVG is a child of our `img` element), we _need_ to have a container that hides overflowing parts. For better performance, we also enforce GPU rendering by applying a `transform` declaration. The biggest caveat with this implementation is the transition of `filter` - users on lower-end devices will probably experience frame drops. Even using `transform` to enforce GPU rendering and using `will-change` as a last resort to hint at the transition does not always fix such issues. In the end, it heavily depends on what devices your end users are on, how big the painted image is on the site, and how many images your site features (that might all blur up at the same time). So should you implement a "blur down" transition? **Probably not.** If you do, strongly consider the caveats. The best animation is the one that engages users, not the one that scares them.

Options

File Methods

Both $file->placeholder() and $file->placeholderUri() file methods support the following options passed as an associative array:

Option Type Default Description
ratio float | null null The ratio of the image. If not set the original image's ratio will be used.
transparent bool | null null Mark the image as transparent. If true, the generated blur will be cropped at the edges. If false, the generated blur will be extended at the edges. By default, the plugin will try to evaluate if the image contains an alpha channel.

Example:

Transparent Images

If you know that your image (e.g. a logo) is transparent, you can pass the transparent option to the placeholderUri() to circumvent artifacts at the edges of the generated blur:

When not explicitly specified, transparency is detected by evaluating the alpha channel of each pixel in the thumbnail image (by the given pixel target). If the image doesn't contain an alpha channel itself, an additional filter is added to the SVG placeholder to remove the alpha channel of the generated blur at the edges.

Image With Ratio

Pass the ratio option to the placeholderUri() method on the original image to generate a placeholder image with a specific ratio:

ℹ️ Kirby doesn't support file methods on cropped images, because the latter inherits the Kirby\Cms\FileVersion class.

Global

Option Default Description
pixel-target 60 Aim for a placeholder image of ~P pixels (w \* h = ~P).
kirbytag.srcset-preset null A preset passed to Kirby's srcset method when using the KirbyTag. If null (default), a src attribute will be rendered instead of srcset.
kirbytag.sizes auto Default for the data-sizes attribute if the KirbyTag works with srcset's.

All of the srcset options have to be wrapped in an array.

Options can be set in your config.php file:

Placeholders in action

Note: GIF is slowed down so as to grasp visually how placeholders look before the image kicks in.

Credits

License

Johann Schopplich


All versions of kirby-blurry-placeholder with dependencies

PHP Build Version
Package Version
Requires getkirby/composer-installer Version ^1.2
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 johannschopplich/kirby-blurry-placeholder contains the following files

Loading the files please wait ....