Skip to content

Commit

Permalink
2.1.0 - Automatic optimization unless optimizePng=false is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
svenrog committed Jul 14, 2020
1 parent 3687e3a commit 4de70d3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ImageResizer.Plugins.PngOptimizer</id>
<version>2.0.0</version>
<version>2.1.0</version>
<title>ImageResizer.Plugins.PngOptimizer</title>
<authors>Geta</authors>
<owners>Geta</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Implementation of nQuant for png optimization. http://nquant.codeplex.com</description>
<copyright>Copyright © Geta 2015</copyright>
<licenseUrl>https://github.com/svenrog/ImageResizer.Plugins.PngOptimizer/blob/master/LICENCE</licenseUrl>
<projectUrl>https://github.com/svenrog/ImageResizer.Plugins.PngOptimizer</projectUrl>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageResizer" version="4.0.5" />
Expand All @@ -17,6 +19,6 @@
</metadata>
<files>
<file src="content\web.config.transform" target="content\web.config.transform" />
<file src="bin\Release\ImageResizer.Plugins.PngOptimizer.dll" target="lib\net45\ImageResizer.Plugins.PngOptimizer.dll" />
<file src="bin\Release\ImageResizer.Plugins.PngOptimizer.dll" target="lib\net452\ImageResizer.Plugins.PngOptimizer.dll" />
</files>
</package>
File renamed without changes.
32 changes: 25 additions & 7 deletions ImageResizer.Plugins.PngOptimizer/PngOptimizerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"];
Expand Down
4 changes: 2 additions & 2 deletions ImageResizer.Plugins.PngOptimizer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
5 changes: 5 additions & 0 deletions build-packages.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cd .\.nuget

.\nuget.exe pack ..\ImageResizer.Plugins.PngOptimizer\ImageResizer.Plugins.PngOptimizer.csproj -Properties Configuration=Release

cd ..\
4 changes: 4 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.CommandLine" version="2.8.2" />
</packages>

0 comments on commit 4de70d3

Please sign in to comment.