diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
index 87fd2582a..0f416cb7b 100644
--- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
@@ -57,5 +57,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets a value indicating whether this instance should write an Adam7 interlaced image.
///
PngInterlaceMode? InterlaceMethod { get; }
+
+ ///
+ /// Gets a value indicating whether this instance should skip certain chunks to decrease file size
+ ///
+ bool Optimized { get; }
}
}
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index 09575bb28..4442bdb0d 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
@@ -155,10 +155,15 @@ namespace SixLabors.ImageSharp.Formats.Png
this.WriteHeaderChunk(stream);
this.WritePaletteChunk(stream, quantized);
this.WriteTransparencyChunk(stream, pngMetadata);
- this.WritePhysicalChunk(stream, metadata);
- this.WriteGammaChunk(stream);
- this.WriteExifChunk(stream, metadata);
- this.WriteTextChunks(stream, pngMetadata);
+
+ if (!this.options.Optimized)
+ {
+ this.WritePhysicalChunk(stream, metadata);
+ this.WriteGammaChunk(stream);
+ this.WriteExifChunk(stream, metadata);
+ this.WriteTextChunks(stream, pngMetadata);
+ }
+
this.WriteDataChunks(image.Frames.RootFrame, quantized, stream);
this.WriteEndChunk(stream);
stream.Flush();
diff --git a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
index dd6c66cb7..5d4be8f14 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Png/PngEncoderOptions.cs
@@ -29,6 +29,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.Quantizer = source.Quantizer;
this.Threshold = source.Threshold;
this.InterlaceMethod = source.InterlaceMethod;
+ this.Optimized = source.Optimized;
}
///
@@ -78,5 +79,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets or sets a value indicating whether this instance should write an Adam7 interlaced image.
///
public PngInterlaceMode? InterlaceMethod { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether this instance should skip certain chunks to decrease file size
+ ///
+ public bool Optimized { get; set; }
}
}