Download the PHP package dodecastudio/craft-blurhash without Composer

On this page you can find all versions of the php package dodecastudio/craft-blurhash. 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 craft-blurhash

BlurHash plugin for Craft CMS

Buy us a tree

Render a BlurHash from a given asset in Craft CMS.

A BlurHash is a compact representation of a placeholder for an image. A blurred version of an image, useful for displaying whilst the full resolution image is loading.

This plugin uses kornrunner's PHP implementation of BlurHash, php-blurhash.

Requirements

Installation

Install the plugin as follows:

  1. Open your terminal and go to your Craft project:

    cd /path/to/project
  2. Then tell Composer to load the plugin:

    composer require dodecastudio/craft-blurhash
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for BlurHash.

BlurHash Overview

The BlurHash plugin will generate a BlurHash image from a craft asset. Here's an example of what you can expect:

Input:

Result:

Using BlurHash

Common use

To use the plugin, first grab an asset from Craft, perhaps something like this:

You can then pass your asset to the plugin's blurhash function, which will return a blurhash image as a data-url, perfect for using in an img element like so:

Note: Due to the compact dimensions of the blurhash image, its aspect ratio may differ fractionally from the source material. Ensure any image markup correctly renders the aspect ratio based on the source markup if you are trying to prevent CLS. One way to achieve this is to use the CSS aspect-ratio property, as used in the example above.

Other features

Generating a blurhash string

If you just want to generate just a blurhash string from a given asset, you can use the blurhash filter like this:

Which will return something like this:

You might want to store this in some way, for use later.

Generating a blurhash image from a blurhash string

If you already have a blurhash string and want to generate an image from it, you can use the blurhashToUri function like this:

Note that blurhash strings do not have any data encoded about the size or scale of the image. You may need additional information in order to display the correct aspect ratio.

Returning average color for an image

BlurHash strings contain the average color for the image. You can decode this value from a BlurHash string and return it as a Craft ColorData object.

...or directly from an asset:

Returning memory info

Images need to be loaded in to memory in order to be read, and a blurhash generated. This helper function will tell you approximately how much memory (in bytes) will be needed for a given image.

GraphQL Support

As of v1.1.0 it's possible to use the plugin via Graph QL. The same functionality that's available with the Twig functions, is now available through Graph QL directives.

Returning a blurhash data URI from an asset field

An asset field can be returned as a data uri to a blurhash image using the @assetToBlurHash directive. It can also be used to return a blurhash string by setting the asUri argument to false.

This will return some JSON which looks a bit something like this:

Rendering a blurhash image from a plaintext blurhash string

If you have a blurhash string saved in a Craft, you can render it to a data URI using the @blurhashToUri directive. In this example, there is a plaintext field called blurhashStringField stored in our news article entry.

And that will then give us some JSON that looks a bit like this:

Getting an average color for an image

If you want to return the average color for an image saved in Craft, you can use the @averageColor directive. This returns a hex color value as a string.

Which will return you some JSON like this:

Settings

Default settings can be overridden. Please see the blurhash-config.php file for details.

Licence 🌳

This package is Treeware. If you use it in production, then we ask that you buy the world a tree.
And why not? By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Thanks! 🙌

Shout-out to @olsp for buying 100 trees and @mokopan for buying 25 trees.

If you've purchased trees through Ecologi, as part of the Treeware license, please let us know for a shout-out.


All versions of craft-blurhash with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
craftcms/cms Version ^3.0|^4.0
kornrunner/blurhash Version ^1.2
treeware/plant Version ^0.1.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 dodecastudio/craft-blurhash contains the following files

Loading the files please wait ....