Skip to content

Fix (gd): preserve alpha in TrimModifier reference color - #1511

Open
cheack wants to merge 1 commit into
Intervention:developfrom
cheack:fix/gd-trim-alpha
Open

Fix (gd): preserve alpha in TrimModifier reference color#1511
cheack wants to merge 1 commit into
Intervention:developfrom
cheack:fix/gd-trim-alpha

Conversation

@cheack

@cheack cheack commented Aug 17, 2026

Copy link
Copy Markdown

Bug

Image::trim() on the GD driver silently no-ops when the image has a transparent margin.

Root cause

TrimModifier::trimColor() averages the four corner pixels' RGB but allocates the imagecropauto() reference color with imagecolorallocate(), which always forces full opacity. When the real corner pixels are transparent, the reference color's alpha never matches them, so imagecropauto() finds nothing within tolerance and crops nothing.

Fix

  • Average and preserve alpha across the four corners.
  • Allocate the reference color with imagecolorallocatealpha() instead of imagecolorallocate().
  • Set imagealphablending(false) / imagesavealpha(true) before sampling, so imagecolorat() returns raw unblended pixel values matching what gets allocated.

@cheack cheack changed the title Fix: preserve alpha in TrimModifier reference color Fix (gd): preserve alpha in TrimModifier reference color Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants