Repository navigation
Fix transparent seam in GD RotateModifier - #1550
Merged
olivervogel merged 1 commit intoOct 10, 2026
Merged
Conversation
The background was painted on the new canvas and a transparent cutout polygon drawn where the rotated image goes, while imagerotate() filled the new areas with a transparent color. The polygon does not match the area covered by imagerotate() exactly, so a seam of transparent pixels was left along the edges of the rotated image on opaque backgrounds. Let imagerotate() fill the new areas with the background color and copy the result without blending, which makes the cutout unnecessary. libgd fills pixels of the transparent color with this color when rotating, so images with a transparent color (GIF, indexed PNG) are first copied to a truecolor image without one. The background is no longer allocated in the frame palette, which returned false on a full palette and made imagerotate() throw a TypeError.
Member
|
Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An oblique
rotate()on an opaque background leaves a seam of transparent pixels along the edges of the rotated image with the GD driver:Imagick gives 0. With a white background the seam is there too, it only shows once the image is on something else than white.
imagerotate()filled the new areas with a transparent color, then the modifier drew a transparent cutout polygon on the background canvas and copied the rotated image over it with blending.imagefilledpolygon()does not cover exactly the same pixels asimagerotate(), so along the edges the transparent fill stays inside the polygon.imagerotate()now gets the background color as fill and the result is copied without blending, so the cutout is gone. On libgd 2.3.3 the edges are also interpolated against the background now, like with Imagick.Frames with a transparent color are first copied to a truecolor image without one. On libgd 2.3.3, at oblique angles,
imagerotate()replaces the pixels of the transparent color with its fill color, so a GIF or indexed PNG would lose its transparency with the new fill.This also fixes a
TypeErroron frames with a full 256 color palette:imagecolorallocatealpha()returnedfalsethere and it went straight toimagerotate().Tests cover the seam, a transparent color at an oblique angle and a full palette. Bundled GD leaves the transparent pixels of
tile.pngandblocks.pngat alpha 126 instead of 127 after the rotation (same on develop), so that test counts alpha >= 120.