Skip to content

Do not store obsolete tRNS chunk data following processing. #2975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/ImageSharp/Formats/Png/PngMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,24 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
/// <inheritdoc/>
public void AfterImageApply<TPixel>(Image<TPixel> destination, Matrix4x4 matrix)
where TPixel : unmanaged, IPixel<TPixel>
=> this.ColorTable = null;
{
this.ColorTable = null;

// If the color type is RGB and we have a transparent color, we need to switch to RGBA
// so that we do not incorrectly preserve the obsolete tRNS chunk.
if (this.ColorType == PngColorType.Rgb && this.TransparentColor.HasValue)
{
this.ColorType = PngColorType.RgbWithAlpha;
this.TransparentColor = null;
}

// The same applies for Grayscale.
if (this.ColorType == PngColorType.Grayscale && this.TransparentColor.HasValue)
{
this.ColorType = PngColorType.GrayscaleWithAlpha;
this.TransparentColor = null;
}
}

/// <inheritdoc/>
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
Expand Down
Loading