2017 © Pedro Peláez
 

neos-plugin neos-sqip

Neos CMS SQIP image renderer

image

shel/neos-sqip

Neos CMS SQIP image renderer

  • Tuesday, June 5, 2018
  • by Sebobo
  • Repository
  • 2 Watchers
  • 11 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Shel.Neos.Sqip

Latest Stable Version Total Downloads License, (*1)

Description

This package provides a fusion object for Neos CMS to render svg image placeholders based on the SQIP technique. They can be used to show a blurry or abstract version of an image while the real image is still lazy loading., (*2)

You can see it in action here., (*3)

Learn more about SQIP is a method to generate SVG based placeholders for images here: * Original node.js version sqip used by this package. * The go variant which is also supported via configuration., (*4)

Attention: the node.js based sqip is not released in version 1 yet. Therefore breaking changes might happen when you use the global binary and you might need to adjust the arguments in the settings or wait for an update of this package., (*5)

Installation

Requires npm (node.js) to work out of the box, although binaries can also be installed manually without it., (*6)

composer require shel/neos-sqip

Ensure the image manipulation library sqip is installed globally., (*7)

Alternatively install them using npm:, (*8)

Globally

npm install -g sqip

Locally

npm install --prefix Packages/Plugins/Shel.Neos.Sqip/Resources/Private/Library

How to use

Use the provided fusion object Shel.Neos.Sqip:ImageTag to render an image with placeholder and use the lazy image loader layzr to lazy load the actual images. This object already provides the necessary attributes to make layzr work out of the box., (*9)

You can also use the provided Shel.Neos.Sqip:SqipImage fusion object to just render the SVG data which you can put into the src attribute of an img tag or in a inline style as background image., (*10)

The fusion object Shel.Neos.Sqip:SqipCaseRenderer provides a renderer for your src attribute which checks if the user is in the backend and then decides to render the original image uri instead of the SQIP image., (*11)

You can use this for example to modify the Carbon.Image:Tag object like this:, (*12)

prototype(Carbon.Image:Tag) {
    attributes {
        src >
        src = Shel.Neos.Sqip:SqipCaseRenderer {
            asset = ${asset}
        }
        srcset >
        data-normal = Carbon.Image:ImageUri
        data-srcset = Carbon.Image:Srcset
    }
}

Compatible image formats

This package was tested with pngs, jpegs and svgs. Possibly other formats work well too., (*13)

Performance

Processing the SQIP placeholders is quite slow and takes several seconds per image., (*14)

To speed this up a thumbnail will be generated first (which can also be prerendered with CLI commands) to reduce the image dimensions. By default the preset from the Media Browser will be used which has dimensions of 250x250. So this is also a bit faster as the media module reuses the same thumbnails., (*15)

You can change the preset via configuration., (*16)

Configuration

Default options

Shel:
  Neos:
    Sqip:
      useGlobalBinary: false # use globally installed binaries
      globalBinaryPath: ''
      library: 'sqip'
      binaryPath: '.bin/sqip'
      arguments: "${'node ' + binaryPath + ' -n ' + numberOfPrimitives + ' -m ' + mode + ' -b ' + blur + ' ' + file}"
      parameters:
        # Customize the number of primitive SVG shapes (default=8) to influence bytesize or level of detail
        numberOfPrimitives: 8
        # Specify the type of primitive shapes that will be used to generate the image
        # 0=combo, 1=triangle, 2=rect, 3=ellipse, 4=circle, 5=rotatedrect, 6=beziers, 7=rotatedellipse, 8=polygon
        mode: 0
        # Set the gaussian blur
        blur: 12
      thumbnailPreset: 'Neos.Media.Browser:Thumbnail'

Using the go variant

The go version is faster than the node.js version and has less dependencies but currently doesn't provide the blur parameter. Both binaries have the same cli output and therefore work fine., (*17)

  1. Install the sqip binary like described in their instructions.
  2. Override the package settings in your own package like this:, (*18)

    Shel:
      Neos:
        Sqip:
          useGlobalBinary: true
          globalBinaryPath: '/path/to/your/go/bin/' # Adapt this to your system
          arguments: "${binaryPath + ' -n ' + numberOfPrimitives + ' -mode ' + mode + ' ' + file}"
          parameters:
            # Customize the number of primitive SVG shapes (default=8) to influence bytesize or level of detail
            numberOfPrimitives: 8
            # Specify the type of primitive shapes that will be used to generate the image
            # 0=combo, 1=triangle, 2=rect, 3=ellipse, 4=circle, 5=rotatedrect, 6=beziers, 7=rotatedellipse, 8=polygon
            mode: 0

Caching

The generated SVGs will be cached in the filesystem as strings., (*19)

To speed the Cache up you can switch to use Redis like this in your Caches.yaml:, (*20)

ShelNeosSqip_ImageCache:
  backend: Neos\Cache\Backend\RedisBackend
  backendOptions:
    database: 0

You can make the cache persistent to keep cached images when temporary caches are flushed:, (*21)

ShelNeosSqip_ImageCache:
  persistent: true

The Versions

05/06 2018

dev-master

9999999-dev

Neos CMS SQIP image renderer

  Sources   Download

MIT

The Requires

 

05/06 2018

0.0.1

0.0.1.0

Neos CMS SQIP image renderer

  Sources   Download

MIT

The Requires