Problem/Motivation

Module is currently only compatible with GD.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review

Summary of changes

New files

  • src/Plugin/ImageToolkit/Operation/PillarboxTrait.php — Shared trait with arguments() and validateArguments() for the pillarbox toolkit operation.
  • src/Plugin/ImageToolkit/Operation/gd/Pillarbox.php — GD toolkit operation: creates a colored canvas via create_new, fills with background color using imagecolorallocate/imagefill, then pastes the original image with imagecopy.
  • src/Plugin/ImageToolkit/Operation/imagemagick/Pillarbox.php — ImageMagick toolkit operation: uses -background, -gravity none, and -extent to achieve the same result in a single IM command.

Modified files

  • src/Plugin/ImageEffect/CropOrFillEffect.php — Major refactoring:
    • Extracted getCropTypeRatio() utility that loads the crop type and validates its aspect ratio in one place. Logs an error when the crop type has no ratio configured (misconfiguration). Returns parsed [width, height] or NULL.
    • Both applyEffect() and transformDimensions() check the ratio immediately at the top — free-form crop types (no ratio) or missing crop types delegate to parent for a standard crop.
    • resolveTargetDimensions() now takes a parsed ratio array instead of a CropType entity. Always returns dimensions (never NULL) since the ratio is pre-validated.
    • Extracted computeCanvasDimensions() shared by applyPillarbox() and transformDimensions().
    • Renamed isOppositeOrientation() to isSameOrientation() (positive logic).
    • All early returns delegate to parent instead of silently returning or returning FALSE.
    • GD-specific code removed — the effect now calls $image->apply('pillarbox', [...]) which is toolkit-agnostic.
  • config/schema/crop_or_fill.schema.yml — Changed bgcolor type from string to color_hex (validatable core type).
  • README.md — Updated to reflect ImageMagick support. Removed GD-only note.

Tests

  • tests/src/Kernel/CropOrFillEffectTest.php — Rewritten with three crop types (landscape 3:2, portrait 2:3, square 1:1) and matching image styles:
    • testSameOrientationCrops — portrait ratio on portrait image → standard crop with pixel verification.
    • testOppositeOrientationFills — landscape ratio on portrait image → pillarbox 540×360 with red background corners.
    • testSquareRatioDoesNotFill — square ratio on portrait image → standard crop (100×100).
    • testTransformDimensionsSameOrientation — portrait ratio predicts crop dimensions.
    • testTransformDimensionsOppositeOrientation — landscape ratio predicts canvas 540×360.
    • testCropTypeRatioIsAlwaysUsed — 0×0 crop entity and no crop entity both produce pillarbox from crop type ratio.

    All 6 tests pass (25 assertions).

  • mably committed 291510dd on 1.x
    feat: #3575608 Compatibility with ImageMagick toolkit
    
    By: mably
    
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.