adachsoft / workflow-step-brand
Brand image-processing steps for AdachSoft Workflow.
Requires
- php: ^8.3
- adachsoft/image-editor-contracts: ^0.2
- adachsoft/image-editor-lib: ^0.2
- adachsoft/workflow: ^7.5
Requires (Dev)
- adachsoft/php-code-style: ^0.8.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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 andadachsoft/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:
| Input | Type | Required | Description |
|---|---|---|---|
image_file | string | One of the pair | Readable path to the source image. |
image_base64 | string | One of the pair | Strict standard base64 image bytes; optional padding is accepted. |
output_format | string | No | jpeg, png, or webp; defaults to jpeg. |
quality | integer | No | Quality from 1 to 100 for JPEG/WebP; defaults to 88. |
output_file | string | No | Destination 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:
| Output | Type | Description |
|---|---|---|
output_file | string, optional | Written path when a destination was supplied. |
image_base64 | string, optional | Encoded image when no destination was supplied. |
width | integer | Final image width in pixels. |
height | integer | Final image height in pixels. |
format | string | Final lowercase format name. |
bytes | integer | Encoded 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.
| Input | Type | Required | Default / constraints |
|---|---|---|---|
width | integer | Yes | Positive canvas width in pixels. |
height | integer | Yes | Positive canvas height in pixels. |
mode | string | No | cover, contain, or contain_blurred_background; defaults to contain_blurred_background. |
anchor | string | No | top_left, top, top_right, left, center, right, bottom_left, bottom, or bottom_right; defaults to center. |
background | string | No | #rgb or #rrggbb color used by contain. |
blur_strength | integer | No | 1–20; defaults to 12. |
background_dim | integer | No | 0–100; defaults to 0. |
brand_watermark
Places an alpha-enabled PNG logo over the source image.
| Input | Type | Required | Default / constraints |
|---|---|---|---|
logo_file | string | One of the pair | Readable path to a PNG logo with alpha transparency. |
logo_base64 | string | One of the pair | Base64 bytes of a PNG logo with alpha transparency. |
anchor | string | No | Same anchor values as brand_fit_image; defaults to bottom_right. |
margin | integer | No | Shared horizontal and vertical margin in pixels; defaults to 24. |
margin_x | integer | No | Optional horizontal margin override; non-negative. |
margin_y | integer | No | Optional vertical margin override; non-negative. |
width_percent | number | No | Logo width as a percentage of the source width; defaults to 20. |
width | integer | No | Absolute logo width in pixels; mutually exclusive with width_percent. |
opacity | integer | No | 0–100; defaults to 100. |
shadow | object or boolean | No | Omitted 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.
| Input | Type | Required | Default / constraints |
|---|---|---|---|
width | integer | No | Canvas width; defaults to 1000. |
height | integer | No | Canvas height; defaults to 1500. |
mode, anchor, background, blur_strength, background_dim | — | No | Same fit settings and defaults as brand_fit_image. |
logo_file / logo_base64 | string | One of the pair | Alpha-enabled PNG logo, supplied by path or base64. |
logo_anchor | string | No | Logo anchor; defaults to bottom_right. |
margin, margin_x, margin_y | integer | No | Same margin rules as brand_watermark; margin defaults to 24. |
logo_width_percent | number | No | Logo width percentage; defaults to 20. |
logo_width | integer | No | Absolute logo width in pixels; mutually exclusive with logo_width_percent. |
opacity | integer | No | Logo opacity from 0 to 100; defaults to 100. |
shadow | object or boolean | No | Defaults 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"
}
}
}