diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs
index 43d7f1ea6..5a79915de 100644
--- a/src/ImageSharp/Formats/Png/PngEncoder.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoder.cs
@@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Formats.Png
public PngInterlaceMode? InterlaceMethod { get; set; }
///
- /// Gets a value indicating whether this instance should skip certain chunks to decrease file size
+ /// Gets or sets a value indicating whether this instance should skip certain chunks to decrease file size
///
public bool Optimized { get; set; }
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 4442bdb0d..8833389e7 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Png
stream.Write(PngConstants.HeaderBytes, 0, PngConstants.HeaderBytes.Length);
this.WriteHeaderChunk(stream);
- this.WritePaletteChunk(stream, quantized);
+ this.WritePaletteChunk(stream, quantized, this.options.Optimized);
this.WriteTransparencyChunk(stream, pngMetadata);
if (!this.options.Optimized)
@@ -552,7 +552,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The pixel format.
/// The containing image data.
/// The quantized frame.
- private void WritePaletteChunk(Stream stream, IQuantizedFrame quantized)
+ /// If optimized make fully transparent pixels black.
+ private void WritePaletteChunk(Stream stream, IQuantizedFrame quantized, bool optimized)
where TPixel : struct, IPixel
{
if (quantized == null)
@@ -584,9 +585,9 @@ namespace SixLabors.ImageSharp.Formats.Png
byte alpha = rgba.A;
- Unsafe.Add(ref colorTableRef, offset) = rgba.R;
- Unsafe.Add(ref colorTableRef, offset + 1) = rgba.G;
- Unsafe.Add(ref colorTableRef, offset + 2) = rgba.B;
+ Unsafe.Add(ref colorTableRef, offset) = optimized && alpha == 0 ? (byte)0 : rgba.R;
+ Unsafe.Add(ref colorTableRef, offset + 1) = optimized && alpha == 0 ? (byte)0 : rgba.G;
+ Unsafe.Add(ref colorTableRef, offset + 2) = optimized && alpha == 0 ? (byte)0 : rgba.B;
if (alpha > this.options.Threshold)
{