/// <summary> /// Returns true when the supplied stream is supported. /// </summary> /// <param name="stream">The stream to check.</param> /// <returns>True when the supplied stream is supported.</returns> public bool IsSupported(Stream stream) { Throw.IfNull(nameof(stream), stream); if (!stream.CanRead || !stream.CanWrite || !stream.CanSeek) { return(false); } return(IsSupported(ImageOptimizerHelper.GetFormatInformation(stream))); }
/// <summary> /// Performs compression on the specified stream. With some formats the image will be decoded /// and encoded and this will result in a small quality reduction. If the new size is not /// smaller the stream won't be overwritten. /// </summary> /// <param name="stream">The stream of the image to compress.</param> /// <returns>True when the image could be compressed otherwise false.</returns> public bool Compress(Stream stream) { ImageOptimizerHelper.CheckStream(stream); var optimizer = GetOptimizer(stream); if (optimizer == null) { return(false); } optimizer.OptimalCompression = OptimalCompression; return(optimizer.Compress(stream)); }
/// <summary> /// Performs lossless compression on the specified stream. If the new stream size is not smaller /// the stream won't be overwritten. /// </summary> /// <param name="stream">The stream of the image to compress.</param> /// <returns>True when the image could be compressed otherwise false.</returns> public bool LosslessCompress([ValidatedNotNull] Stream stream) { ImageOptimizerHelper.CheckStream(stream); var optimizer = GetOptimizer(stream); if (optimizer == null) { return(false); } optimizer.OptimalCompression = OptimalCompression; return(optimizer.LosslessCompress(stream)); }
private IImageOptimizer GetOptimizer(Stream stream) { var info = ImageOptimizerHelper.GetFormatInformation(stream); return(GetOptimizer(info)); }
private IImageOptimizer GetOptimizer(FileInfo file) { var info = ImageOptimizerHelper.GetFormatInformation(file); return(GetOptimizer(info)); }
/// <summary> /// Returns true when the supplied file name is supported based on the extension of the file. /// </summary> /// <param name="fileName">The name of the file to check.</param> /// <returns>True when the supplied file name is supported based on the extension of the file.</returns> public bool IsSupported(string fileName) => IsSupported(ImageOptimizerHelper.GetFormatInformation(fileName));
/// <summary> /// Returns true when the supplied file name is supported based on the extension of the file. /// </summary> /// <param name="file">The file to check.</param> /// <returns>True when the supplied file name is supported based on the extension of the file.</returns> /// <returns>True when the image could be compressed otherwise false.</returns> public bool IsSupported(FileInfo file) => IsSupported(ImageOptimizerHelper.GetFormatInformation(file));