Skip to content

Commit dd06da4

Browse files
Fix #2974
1 parent 0843217 commit dd06da4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/ImageSharp/Formats/Png/PngMetadata.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,24 @@ public FormatConnectingMetadata ToFormatConnectingMetadata()
230230
/// <inheritdoc/>
231231
public void AfterImageApply<TPixel>(Image<TPixel> destination, Matrix4x4 matrix)
232232
where TPixel : unmanaged, IPixel<TPixel>
233-
=> this.ColorTable = null;
233+
{
234+
this.ColorTable = null;
235+
236+
// If the color type is RGB and we have a transparent color, we need to switch to RGBA
237+
// so that we do not incorrectly preserve the obsolete tRNS chunk.
238+
if (this.ColorType == PngColorType.Rgb && this.TransparentColor.HasValue)
239+
{
240+
this.ColorType = PngColorType.RgbWithAlpha;
241+
this.TransparentColor = null;
242+
}
243+
244+
// The same applies for Grayscale.
245+
if (this.ColorType == PngColorType.Grayscale && this.TransparentColor.HasValue)
246+
{
247+
this.ColorType = PngColorType.GrayscaleWithAlpha;
248+
this.TransparentColor = null;
249+
}
250+
}
234251

235252
/// <inheritdoc/>
236253
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();

0 commit comments

Comments
 (0)