diff --git a/ImageResizer.Plugins.PngOptimizer/ImageResizer.Plugins.PngOptimizer.nuspec b/ImageResizer.Plugins.PngOptimizer/ImageResizer.Plugins.PngOptimizer.nuspec index 57899ad..f1ec5be 100644 --- a/ImageResizer.Plugins.PngOptimizer/ImageResizer.Plugins.PngOptimizer.nuspec +++ b/ImageResizer.Plugins.PngOptimizer/ImageResizer.Plugins.PngOptimizer.nuspec @@ -2,13 +2,15 @@ ImageResizer.Plugins.PngOptimizer - 2.0.0 + 2.1.0 ImageResizer.Plugins.PngOptimizer Geta Geta - false + true Implementation of nQuant for png optimization. http://nquant.codeplex.com Copyright © Geta 2015 + https://github.com/svenrog/ImageResizer.Plugins.PngOptimizer/blob/master/LICENCE + https://github.com/svenrog/ImageResizer.Plugins.PngOptimizer @@ -17,6 +19,6 @@ - + \ No newline at end of file diff --git a/ImageResizer.Plugins.PngOptimizer/LICENCE b/ImageResizer.Plugins.PngOptimizer/LICENCE.txt similarity index 100% rename from ImageResizer.Plugins.PngOptimizer/LICENCE rename to ImageResizer.Plugins.PngOptimizer/LICENCE.txt diff --git a/ImageResizer.Plugins.PngOptimizer/PngOptimizerPlugin.cs b/ImageResizer.Plugins.PngOptimizer/PngOptimizerPlugin.cs index 141f0df..290a73f 100644 --- a/ImageResizer.Plugins.PngOptimizer/PngOptimizerPlugin.cs +++ b/ImageResizer.Plugins.PngOptimizer/PngOptimizerPlugin.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; +using System.IO; using ImageResizer.Configuration; using ImageResizer.Plugins.PngOptimizer.Analyzers; using ImageResizer.Plugins.PngOptimizer.Quantization; @@ -103,27 +104,44 @@ protected virtual byte GetDitherSetting(ImageState state) protected virtual bool DetermineEnabled(ImageState state) { - if (state.destBitmap == null) return false; + if (state == null) return false; if (state.settings == null) return false; + if (state.destBitmap == null) return false; - var setting = state.settings["optimizePng"]; + var setting = state.settings["optimizePng"] ?? string.Empty; - if (string.IsNullOrEmpty(setting)) return IsPngFile(state); if (setting == "0") return false; if (setting.Equals("false", StringComparison.InvariantCultureIgnoreCase)) return false; - return true; + return IsPngFile(state); } protected virtual bool IsPngFile(ImageState state) { - if (state.Job == null) return false; - - var extension = state.Job.ResultFileExtension ?? string.Empty; + var extension = state.Job?.ResultFileExtension ?? + GetExtension(state.sourceBitmap) ?? + string.Empty; return extension.Equals("png", StringComparison.InvariantCultureIgnoreCase); } + public string GetExtension(Bitmap source) + { + if (source == null) + return null; + + var tag = source.Tag as BitmapTag; + if (tag == null) + return null; + + var path = tag.Path; + if (string.IsNullOrEmpty(path)) + return null; + + return Path.GetExtension(path) + .TrimStart('.'); + } + protected virtual bool DetermineDebug(ImageState state) { var setting = state.settings["optimizePngDebug"]; diff --git a/ImageResizer.Plugins.PngOptimizer/Properties/AssemblyInfo.cs b/ImageResizer.Plugins.PngOptimizer/Properties/AssemblyInfo.cs index 7a27898..8f32a39 100644 --- a/ImageResizer.Plugins.PngOptimizer/Properties/AssemblyInfo.cs +++ b/ImageResizer.Plugins.PngOptimizer/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/build-packages.ps1 b/build-packages.ps1 new file mode 100644 index 0000000..67c81ef --- /dev/null +++ b/build-packages.ps1 @@ -0,0 +1,5 @@ +cd .\.nuget + +.\nuget.exe pack ..\ImageResizer.Plugins.PngOptimizer\ImageResizer.Plugins.PngOptimizer.csproj -Properties Configuration=Release + +cd ..\ \ No newline at end of file diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..0901fde --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file