Skip to content

fix: support text rotation in collage zone mode and respect admin set…#1465

Open
flacoonb wants to merge 2 commits intoPhotoboothProject:devfrom
flacoonb:fix/collage-text-zone-rotation
Open

fix: support text rotation in collage zone mode and respect admin set…#1465
flacoonb wants to merge 2 commits intoPhotoboothProject:devfrom
flacoonb:fix/collage-text-zone-rotation

Conversation

@flacoonb
Copy link
Contributor

fix: support text rotation in collage zone mode and respect admin settings

Previously, the text rotation configured in the admin panel was ignored when
using collage layouts with zone-based text alignment (text_alignment.mode = "zone").
The zone rendering in Image::applyTextInZone() always passed rotation=0 to
imagettftext(), and Collage.php allowed JSON layout files to override the admin
rotation value.

Changes in Collage.php:

  • Zone-based text alignment from layout JSON is now only applied when
    "Allow layout selection" (collageAllowSelection) is enabled. When
    disabled, admin panel coordinates (locationx, locationy, rotation)
    are used directly via legacy rendering
  • Admin rotation value always takes priority over JSON layout rotation
    in both zone mode and legacy mode when layout selection is active
  • text_disabled from JSON is also only honored when layout selection
    is enabled

Changes in Image.php:

  • applyTextInZone() now applies the configured rotation angle to
    imagettftext() instead of hardcoding 0
  • Rotated text lines are stacked perpendicular to the text direction
    using trigonometric offset calculation (sin/cos) so lines appear
    properly aligned at any angle
  • Each line is individually centered along the text direction based on
    its width relative to the widest line
  • The entire rotated text block is precisely centered within the text
    zone by calculating the actual bounding box of all rendered glyphs
    using imagettfbbox() with the rotation angle, then computing the
    offset needed for proper horizontal (align) and vertical (valign)
    zone alignment
  • Admin line spacing (linespace) is respected as minimum distance
    between lines, preventing text from collapsing when auto-fit reduces
    the font size
  • Removed outdated comment "currently only 0 supported" from
    textZoneRotation property

Closes #1433

Prerequisites checklist

What is the purpose of this pull request? (put an "x" next to an item)

  • Documentation update
  • Bug fix
  • New feature
  • Other, please explain:

What changes did you make? (Give an overview)

When collage.allow_selection is enabled and the user selects a collage layout
with zone-based text alignment (text_alignment.mode = "zone"), the text rotation
configured in the admin panel was completely ignored. The text was always rendered
at 0 degrees regardless of the admin setting.

Root cause: Two issues:

  1. Image::applyTextInZone() hardcoded rotation=0 in the imagettftext() call,
    ignoring the textZoneRotation property entirely
  2. Collage.php allowed JSON layout files to override the admin rotation value
    (most layouts set rotation: 0 explicitly)

Fix:

  • Admin rotation always takes priority over JSON layout rotation
  • Zone-based text alignment is only applied when layout selection is enabled;
    when disabled, admin coordinates (locationx, locationy, rotation) are used directly
  • applyTextInZone() now properly renders rotated text with correct line stacking
    (perpendicular to text direction using sin/cos), per-line centering along the text
    direction, and precise bounding-box-based centering within the text zone
  • Admin line spacing is respected as minimum value even when auto-fit reduces font size

Is there anything you'd like reviewers to focus on?

  • The rotated text rendering logic in Image::applyTextInZone(): it uses
    imagettfbbox() with the actual rotation angle to compute the precise bounding
    box of the entire text block, then centers it within the zone. This approach
    works correctly for any rotation angle (-359 to 359).
  • The $c->collageAllowSelection guard on text_alignment processing in
    Collage.php: this ensures that when layout selection is disabled, the admin
    has full control over text positioning via locationx/locationy/rotation.

AI used to create this Pull Request?

Yes, Claude Code (claude-sonnet-4-6) was used to assist with:

  • Analyzing the rendering pipeline to identify the root cause
  • Implementing the trigonometric text positioning for rotated zone text
  • Running local CI checks (PHPStan, PHPUnit, PHP Lint, pre-commit hooks)

Photobooth and others added 2 commits February 19, 2026 15:30
…tings

Previously, the text rotation configured in the admin panel was ignored
when using collage layouts with zone-based text alignment
(text_alignment.mode = "zone"). The zone rendering in Image::applyTextInZone()
always passed rotation=0 to imagettftext(), and Collage.php allowed JSON
layout files to override the admin rotation value.

Changes in Collage.php:
- Zone-based text alignment from layout JSON is now only applied when
  "Allow layout selection" (collageAllowSelection) is enabled. When
  disabled, admin panel coordinates (locationx, locationy, rotation)
  are used directly via legacy rendering
- Admin rotation value always takes priority over JSON layout rotation
  in both zone mode and legacy mode when layout selection is active
- text_disabled from JSON is also only honored when layout selection
  is enabled

Changes in Image.php:
- applyTextInZone() now applies the configured rotation angle to
  imagettftext() instead of hardcoding 0
- Rotated text lines are stacked perpendicular to the text direction
  using trigonometric offset calculation (sin/cos) so lines appear
  properly aligned at any angle
- Each line is individually centered along the text direction based on
  its width relative to the widest line
- The entire rotated text block is precisely centered within the text
  zone by calculating the actual bounding box of all rendered glyphs
  using imagettfbbox() with the rotation angle, then computing the
  offset needed for proper horizontal (align) and vertical (valign)
  zone alignment
- Admin line spacing (linespace) is respected as minimum distance
  between lines, preventing text from collapsing when auto-fit reduces
  the font size
- Removed outdated comment "currently only 0 supported" from
  textZoneRotation property

Closes PhotoboothProject#1433
@andi34 andi34 added the collage label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: text_alignment ignored when collage.allow_selection is disabled

2 participants