Create a base64-encoded transparent pixel of the given width and height
Pixels once generated are cached on a width * height basis to reduce load
This plugin requires Craft CMS 3.0.0-RC1 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require tibemolde/placeholder-pixel
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Placeholder Pixel.
Create a base64-encoded transparent pixel of the given width and height
No configuration is needed outside of runtime-options
Base usage:
craft.placeholderPixel.get(options)
Default options:
{
width : 1,
height : 1,
aspectRatio : {
w: 16,
h: 10
}
}
Examples:
-
1 x 1 pixel:
<img src="{{ craft.placeholderPixel.get }}" alt="">
-
Pixel with two specific dimensions:
<img src="{{ craft.placeholderPixel.get({width: 64, height: 64}) }}" alt="">
-
Pixel with one specific dimension and default aspect-ratio:
<img src="{{ craft.placeholderPixel.get({width: 1024}) }}" alt="">
-
Pixel with one specific dimension and specific aspect-ratio:
<img src="{{ craft.placeholderPixel.get({width: 1024, aspectRatio: {w: 5, h: 4}}) }}" alt="">
Some things to do, and ideas for potential features:
- Make it better, somehow? :o
Brought to you by TIBE Molde