Browse Source

4.1.4 and 1.0.0

Updates ImageProcessor.Web to 4.1.4 and add
ImageProcessor.Web.PostProcessor 1.0.0


Former-commit-id: 40a13bd8426a8680eb93b9d676a4d635baad066a
Former-commit-id: 2e08bf7acea5664ab93d7705d54ac4e896fbebad
af/merge-core
James South 11 years ago
parent
commit
d0cf2843a4
  1. 32
      build/NuSpecs/ImageProcessor.Web.PostProcessor.nuspec
  2. 2
      build/NuSpecs/ImageProcessor.Web.nuspec
  3. 13
      build/build.xml
  4. 25
      src/ImageProcessor.Web.PostProcessor/ApplicationEvents.cs
  5. 16
      src/ImageProcessor.Web.PostProcessor/PostProcessingResultEventArgs.cs
  6. 40
      src/ImageProcessor.Web.PostProcessor/PostProcessor.cs
  7. 10
      src/ImageProcessor.Web.PostProcessor/Properties/AssemblyInfo.cs

32
build/NuSpecs/ImageProcessor.Web.PostProcessor.nuspec

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ImageProcessor.Web.PostProcessor</id>
<version>1.0.0.0</version>
<title>ImageProcessor.Web.PostProcessor</title>
<authors>James South</authors>
<owners>James South</owners>
<projectUrl>http://imageprocessor.org</projectUrl>
<iconUrl>http://imageprocessor.org/assets/ico/apple-touch-icon-144x144.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Applies various image compression tools to further optimize cached .png, .gif, and .jpg images.
If you use ImageProcessor please get in touch via my twitter @james_m_south
Feedback is always welcome</description>
<summary>ImageProcessor.Web PostProcessor for ASP.NET websites.</summary>
<releaseNotes />
<copyright>James South</copyright>
<language>en-GB</language>
<tags>Image Resize Crop Rotate Quality Watermark Gif Jpg Jpeg Bitmap Png Tiff ASP Cache EXIF</tags>
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="ImageProcessor" version="2.1.0.0" />
<dependency id="ImageProcessor.Web" version="4.1.4.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\_BuildOutput\ImageProcessor.Web.PostProcessor\lib\net45\ImageProcessor.Web.PostProcessor.dll" target="lib\net45\ImageProcessor.Web.PostProcessor.dll" />
</files>
</package>

2
build/NuSpecs/ImageProcessor.Web.nuspec

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ImageProcessor.Web</id>
<version>4.1.3.0</version>
<version>4.1.4.0</version>
<title>ImageProcessor.Web</title>
<authors>James South</authors>
<owners>James South</owners>

13
build/build.xml

@ -13,7 +13,7 @@
<project>
<name>ImageProcessor Web</name>
<version>4.1.3.0</version>
<version>4.1.4.0</version>
<folder>..\src\ImageProcessor.Web</folder>
<projfile>ImageProcessor.Web.csproj</projfile>
<outputs>
@ -22,6 +22,17 @@
<nuspec>ImageProcessor.Web.nuspec</nuspec>
</project>
<project>
<name>ImageProcessor Web PostProcessor</name>
<version>1.0.0.0</version>
<folder>..\src\ImageProcessor.Web.PostProcessor</folder>
<projfile>ImageProcessor.Web.PostProcessor.csproj</projfile>
<outputs>
<output folder="ImageProcessor.Web.PostProcessor\lib\net45" />
</outputs>
<nuspec>ImageProcessor.Web.PostProcessor.nuspec</nuspec>
</project>
<project>
<name>ImageProcessor Web.config sample</name>
<version>2.1.0.0</version>

25
src/ImageProcessor.Web.PostProcessor/ApplicationEvents.cs

@ -1,10 +1,10 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageProcessingModule.cs" company="James South">
// <copyright file="ApplicationEvents.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// PostProcesses any image requests within the web application.
// Binds the PostProcessor to process any image requests within the web application.
// Many thanks to Azure Image Optimizer <see href="https://github.com/ligershark/AzureJobs"/>
// </summary>
// --------------------------------------------------------------------------------------------------------------------
@ -12,25 +12,38 @@
using System.Web;
[assembly: PreApplicationStartMethod(typeof(ImageProcessor.Web.PostProcessor.ApplicationEvents), "Start")]
namespace ImageProcessor.Web.PostProcessor
{
using ImageProcessor.Web.Helpers;
using ImageProcessor.Web.HttpModules;
/// <summary>
/// PostProcesses any image requests within the web application.
/// Binds the PostProcessor to process any image requests within the web application.
/// Many thanks to Azure Image Optimizer <see href="https://github.com/ligershark/AzureJobs"/>
/// </summary>
public static class ApplicationEvents
{
/// <summary>
/// The initial startup method.
/// </summary>
public static void Start()
{
ImageProcessingModule.OnPostProcessing += PostProcess;
ImageProcessingModule.OnPostProcessing += PostProcessAsync;
}
private static async void PostProcess(object sender, PostProcessingEventArgs e)
/// <summary>
/// Asynchronously post-processes cached images.
/// </summary>
/// <param name="sender">
/// The source of the event.
/// </param>
/// <param name="e">
/// An <see cref="PostProcessingEventArgs">EventArgs</see> that contains the event data.
/// </param>
private static async void PostProcessAsync(object sender, PostProcessingEventArgs e)
{
await PostProcessor.PostProcessImage(e.CachedImagePath);
await PostProcessor.PostProcessImageAsync(e.CachedImagePath);
}
}
}

16
src/ImageProcessor.Web.PostProcessor/PostProcessingResultEventArgs.cs

@ -45,27 +45,27 @@ namespace ImageProcessor.Web.PostProcessor
}
/// <summary>
/// Gets the original file size in bytes.
/// Gets or sets the original file size in bytes.
/// </summary>
public long OriginalFileSize { get; set; }
/// <summary>
/// Gets the original file name.
/// Gets or sets the original file name.
/// </summary>
public string OriginalFileName { get; set; }
/// <summary>
/// Gets the result file size in bytes.
/// Gets or sets the result file size in bytes.
/// </summary>
public long ResultFileSize { get; set; }
/// <summary>
///
/// Gets or sets the result file name.
/// </summary>
public string ResultFileName { get; set; }
/// <summary>
/// Gets the difference in filesize in bytes.
/// Gets the difference in file size in bytes.
/// </summary>
public long Saving
{
@ -73,13 +73,13 @@ namespace ImageProcessor.Web.PostProcessor
}
/// <summary>
/// Gets the difference in filesize as a percentage.
/// Gets the difference in file size as a percentage.
/// </summary>
public double Percent
{
get
{
return Math.Round(100 - this.ResultFileSize / (double)this.OriginalFileSize * 100, 1);
return Math.Round(100 - ((this.ResultFileSize / (double)this.OriginalFileSize) * 100), 1);
}
}
@ -95,7 +95,7 @@ namespace ImageProcessor.Web.PostProcessor
stringBuilder.AppendLine("Optimized " + Path.GetFileName(this.OriginalFileName));
stringBuilder.AppendLine("Before: " + this.OriginalFileSize + " bytes");
stringBuilder.AppendLine("After: " + this.ResultFileSize + " bytes");
stringBuilder.AppendLine("Saving: " + this.Saving + " bytes / " + Percent + "%");
stringBuilder.AppendLine("Saving: " + this.Saving + " bytes / " + this.Percent + "%");
return stringBuilder.ToString();
}

40
src/ImageProcessor.Web.PostProcessor/PostProcessor.cs

@ -23,10 +23,19 @@ namespace ImageProcessor.Web.PostProcessor
/// </summary>
internal static class PostProcessor
{
public async static Task PostProcessImage(string sourceFile)
/// <summary>
/// Post processes the image asynchronously.
/// </summary>
/// <param name="sourceFile">
/// The source file.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public static async Task PostProcessImageAsync(string sourceFile)
{
string targetFile = Path.GetTempFileName();
PostProcessingResultEventArgs result = await RunProcessAsync(sourceFile, targetFile);
PostProcessingResultEventArgs result = await RunProcess(sourceFile, targetFile);
if (result != null && result.Saving > 0 && result.ResultFileSize > 0)
{
@ -39,7 +48,19 @@ namespace ImageProcessor.Web.PostProcessor
}
}
private static Task<PostProcessingResultEventArgs> RunProcessAsync(string sourceFile, string targetFile)
/// <summary>
/// Runs the process to optimize the images.
/// </summary>
/// <param name="sourceFile">
/// The source file.
/// </param>
/// <param name="targetFile">
/// The target file.
/// </param>
/// <returns>
/// The <see cref="Task{PostProcessingResultEventArgs}"/> containing post-processing information.
/// </returns>
private static Task<PostProcessingResultEventArgs> RunProcess(string sourceFile, string targetFile)
{
TaskCompletionSource<PostProcessingResultEventArgs> tcs = new TaskCompletionSource<PostProcessingResultEventArgs>();
ProcessStartInfo start = new ProcessStartInfo("cmd")
@ -74,6 +95,18 @@ namespace ImageProcessor.Web.PostProcessor
return tcs.Task;
}
/// <summary>
/// Gets the correct arguments to pass to the post-processor.
/// </summary>
/// <param name="sourceFile">
/// The source file.
/// </param>
/// <param name="targetFile">
/// The target file.
/// </param>
/// <returns>
/// The <see cref="string"/> containing the correct command arguments.
/// </returns>
private static string GetArguments(string sourceFile, string targetFile)
{
if (!Uri.IsWellFormedUriString(sourceFile, UriKind.RelativeOrAbsolute) && !File.Exists(sourceFile))
@ -105,6 +138,7 @@ namespace ImageProcessor.Web.PostProcessor
case ".gif":
return string.Format(CultureInfo.CurrentCulture, "/c gifsicle --crop-transparency --no-comments --no-extensions --no-names --optimize=3 --batch \"{0}\" --output=\"{1}\"", sourceFile, targetFile);
}
return null;
}
}

10
src/ImageProcessor.Web.PostProcessor/Properties/AssemblyInfo.cs

@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -6,11 +6,11 @@ using System.Runtime.InteropServices;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ImageProcessor.Web.PostProcessor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Post-processes cached images to further reduce file size.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("James South")]
[assembly: AssemblyProduct("ImageProcessor.Web.PostProcessor")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyCopyright("Copyright © James South")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
//
// 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("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Loading…
Cancel
Save