smallpics/imagerx-smallpics

Small Pics transformer for Imager X

Installs: 2 489

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Type:craft-plugin

pkg:composer/smallpics/imagerx-smallpics

1.0.1 2025-11-18 18:31 UTC

This package is auto-updated.

Last update: 2025-11-18 18:32:02 UTC


README

This module provides an Small Pics transformer for Imager X.

Requirements

  • Craft CMS 5.0.0+
  • Imager X 5.1.0+
  • PHP 8.2+

Installation

composer require smallpics/imagerx-smallpics
php craft plugin/install imagerx-smallpics

Configuration

Add the Small Pics configuration to your Imager X Small Pics transformer config file (config/imagerx-smallpics.php):

Single origin config

return [
    'baseUrl' => getenv('SMALLPICS_BASE_URL'),
    'secret' => getenv('SMALLPICS_SECRET') ?: null,
    'defaultParams' => [],
];

Multi-origin config

It is possible to configure multiple origins. You can then select the origin to use when transforming an image by setting the origin key in the transformerParams array.

return [
    'defaultParams' => [
        'format' => 'webp',
    ],
    'origins' => [
        \smallpics\imagerx\smallpics\models\Settings::DEFAULT_ORIGIN_NAME => [ // Or simply 'default'
            'baseUrl' => getenv('SMALLPICS_DEFAULT_ORIGIN_BASE_URL'),
            'secret' => getenv('SMALLPICS_DEFAULT_ORIGIN_SECRET') ?: null,
            'defaultParams' => [
                'quality' => 80,
            ],
        ],
        'origin2' => [
            'baseUrl' => getenv('SMALLPICS_ORIGIN2_BASE_URL'),
            'secret' => getenv('SMALLPICS_ORIGIN2_SECRET') ?: null,
            'defaultParams' => [
                'format' => 'png',
                'quality' => 90
            ],
        ],
    ],
];

You can also set the name of the default origin by setting the defaultOrigin key in the config:

return [
    'defaultOrigin' => 'spaces',
    'origins' => [
        'spaces' => [
            'baseUrl' => getenv('SMALLPICS_SPACES_BASE_URL'),
            // ...
        ],
        's3' => [
            'baseUrl' => getenv('SMALLPICS_S3_BASE_URL'),
            // ...
        ],
    ],
];

Usage

Once installed and configured, you can use the transformer with Imager X:

{% set transformedImages = craft.imagerx.transformImage(rawImage, [
  { width: 74, height: 74 },
  { width: 120, height: 120 },
  { width: 172, height: 172 },
  { width: 254, height: 254 }
], {
  mode: 'crop',
  transformerParams: {
    padding: 10,
    background: 'ff0000',
    border: {
      width: 10,
      color: '000000',
      borderMethod: 'overlay',
    }
  },
}) %}

Multi-origin usage

{% set transformedImages = craft.imagerx.transformImage(rawImage, [
  { width: 74, height: 74 },
  { width: 120, height: 120 },
  { width: 172, height: 172 },
  { width: 254, height: 254 }
], {
  mode: 'crop',
  transformerParams: {
    origin: 'origin2',
    padding: 10,
    background: 'ff0000',
    border: {
      width: 10,
      color: '000000',
      borderMethod: 'overlay',
    }
  },
}) %}

Notes

Take a look at the Small Pics API for a list of available options to use in the defaultParams and transformerParams arrays.

This transformer uses smallpics/smallpics-php under the hood. Take a look there for more usage information.