Search by

adachsoft / workflow-step-brand

Arkadiusz Adach

Brand image-processing steps for AdachSoft Workflow.

Package info

gitlab.com/a.adach/workflow-step-brand

Issues

pkg:composer/adachsoft/workflow-step-brand

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-29 17:33 UTC

This package is auto-updated.

Last update: 2026-11-29 16:34:10 UTC


README

Brand image-processing steps for adachsoft/workflow. This stage provides image composition used to publish branded Pinterest pins: fit a photo to a canvas, add a transparent PNG logo, or do both in one editor request.

Installation

composer require adachsoft/workflow-step-brand

The package uses adachsoft/image-editor-contracts and the GD implementation from adachsoft/image-editor-lib. The default editor is GdImageEditor; the package therefore requires the GD extension through its image-editor dependency.

Requirements

  • PHP 8.3 or newer.
  • adachsoft/workflow ^7.5.
  • adachsoft/image-editor-contracts ^0.2 and adachsoft/image-editor-lib ^0.2.
  • GD extension (ext-gd) for the default editor.

Usage

Registering the steps

Register the step classes with the workflow step registry:

use AdachSoft\Workflow\Registry\InMemoryStepRegistry;
use AdachSoft\WorkflowStepBrand\Steps\BrandFitImageStep;
use AdachSoft\WorkflowStepBrand\Steps\BrandPinImageStep;
use AdachSoft\WorkflowStepBrand\Steps\BrandWatermarkStep;

$stepRegistry = new InMemoryStepRegistry();
$stepRegistry->register(BrandFitImageStep::class);
$stepRegistry->register(BrandWatermarkStep::class);
$stepRegistry->register(BrandPinImageStep::class);

Each step accepts an optional ImageEditorInterface in its constructor. When no editor is injected, it creates a GdImageEditor. To use a configured editor instance, register a step instance:

$stepRegistry->registerInstance(
    BrandPinImageStep::class,
    new BrandPinImageStep($imageEditor),
);

Configure both on_next and on_error targets for each registered step.

Shared inputs and outputs

Each step requires exactly one source field:

InputTypeRequiredDescription
image_filestringOne of the pairReadable path to the source image.
image_base64stringOne of the pairStrict standard base64 image bytes; optional padding is accepted.
output_formatstringNojpeg, png, or webp; defaults to jpeg.
qualityintegerNoQuality from 1 to 100 for JPEG/WebP; defaults to 88.
output_filestringNoDestination path. Parent directories are created and the file is replaced atomically.

When output_file is omitted, the success output contains image_base64. When it is supplied, the image is written there and the output contains output_file instead of image_base64.

Every successful branch returns:

OutputTypeDescription
output_filestring, optionalWritten path when a destination was supplied.
image_base64string, optionalEncoded image when no destination was supplied.
widthintegerFinal image width in pixels.
heightintegerFinal image height in pixels.
formatstringFinal lowercase format name.
bytesintegerEncoded image size in bytes.

The on_error branch returns an error string. Error messages redact string values from step input. Image inputs are limited to 25 MiB and 40 megapixels; edited output is limited to 40 megapixels and 25 MiB, with a maximum of 20 operations per request.

brand_fit_image

Fits one source image to the requested dimensions. cover crops to fill the canvas; contain keeps the complete source and fills unused space with background; contain_blurred_background keeps the complete source over a blurred, cover-scaled background.

InputTypeRequiredDefault / constraints
widthintegerYesPositive canvas width in pixels.
heightintegerYesPositive canvas height in pixels.
modestringNocover, contain, or contain_blurred_background; defaults to contain_blurred_background.
anchorstringNotop_left, top, top_right, left, center, right, bottom_left, bottom, or bottom_right; defaults to center.
backgroundstringNo#rgb or #rrggbb color used by contain.
blur_strengthintegerNo1–20; defaults to 12.
background_dimintegerNo0–100; defaults to 0.

brand_watermark

Places an alpha-enabled PNG logo over the source image.

InputTypeRequiredDefault / constraints
logo_filestringOne of the pairReadable path to a PNG logo with alpha transparency.
logo_base64stringOne of the pairBase64 bytes of a PNG logo with alpha transparency.
anchorstringNoSame anchor values as brand_fit_image; defaults to bottom_right.
marginintegerNoShared horizontal and vertical margin in pixels; defaults to 24.
margin_xintegerNoOptional horizontal margin override; non-negative.
margin_yintegerNoOptional vertical margin override; non-negative.
width_percentnumberNoLogo width as a percentage of the source width; defaults to 20.
widthintegerNoAbsolute logo width in pixels; mutually exclusive with width_percent.
opacityintegerNo0–100; defaults to 100.
shadowobject or booleanNoOmitted or false disables the shadow; true selects the default soft black shadow.

A shadow object accepts offset_x, offset_y, blur, opacity, and color. Missing properties use the soft-shadow defaults (4, 6, 6, 55, and #000000). Offsets are limited to -200–200 pixels, blur to 0–20, opacity to 0–100, and color to #rgb or #rrggbb.

brand_pin_image

Combines fitting and logo overlay in one ImageEditRequestDto and one editor call, so the source is decoded and encoded once. It is the convenience step for Pinterest pins.

InputTypeRequiredDefault / constraints
widthintegerNoCanvas width; defaults to 1000.
heightintegerNoCanvas height; defaults to 1500.
mode, anchor, background, blur_strength, background_dim—NoSame fit settings and defaults as brand_fit_image.
logo_file / logo_base64stringOne of the pairAlpha-enabled PNG logo, supplied by path or base64.
logo_anchorstringNoLogo anchor; defaults to bottom_right.
margin, margin_x, margin_yintegerNoSame margin rules as brand_watermark; margin defaults to 24.
logo_width_percentnumberNoLogo width percentage; defaults to 20.
logo_widthintegerNoAbsolute logo width in pixels; mutually exclusive with logo_width_percent.
opacityintegerNoLogo opacity from 0 to 100; defaults to 100.
shadowobject or booleanNoDefaults to the soft black shadow; false disables it.

Pinterest workflow fragment

The downloader and social-post types below are supplied by the host application and adachsoft/workflow-step-social. The workflow context provides photo_url, brand_logo_file, and branded_pin_file; the downloader writes its downloaded path to image_file.

{
  "download_photo": {
    "type": "download_photo",
    "input_map": {
      "url": "$context.photo_url"
    },
    "output_map": {
      "image_file": "$context.image_file"
    },
    "config": {
      "on_next": "brand_pin",
      "on_error": "handle_error"
    }
  },
  "brand_pin": {
    "type": "brand_pin_image",
    "input_map": {
      "image_file": "$context.image_file",
      "logo_file": "$context.brand_logo_file",
      "width": 1000,
      "height": 1500,
      "output_format": "jpeg",
      "output_file": "$context.branded_pin_file"
    },
    "config": {
      "on_next": "social_post",
      "on_error": "handle_error"
    }
  },
  "social_post": {
    "type": "social_post",
    "input_map": {
      "image_file": "$context.branded_pin_file"
    },
    "config": {
      "on_next": "finish",
      "on_error": "handle_error"
    }
  }
}