From 22205f95c53d9b2eb6df6986a6bfd7ce7d8c08ca Mon Sep 17 00:00:00 2001 From: James South Date: Mon, 3 Feb 2014 15:26:07 +0000 Subject: [PATCH 1/2] Update README.md Former-commit-id: 004ba138f0543bfa218019cd7a44ecfaa29d1507 --- README.md | 234 +----------------------------------------------------- 1 file changed, 1 insertion(+), 233 deletions(-) diff --git a/README.md b/README.md index a891a3a50..a682ace93 100644 --- a/README.md +++ b/README.md @@ -5,236 +5,4 @@ Imageprocessor is a lightweight library written in C# that allows you to manipul It's fast, extensible, easy to use, comes bundled with some great features and is fully open source. -Core plugins at present include: - - - Alpha (Sets opacity) - - Brightness - - Contrast - - Crop - - Filter (Image filters including sepia, greyscale, blackwhite, lomograph, polaroid, comic, gotham, hisatch, losatch) - - Flip (Flip the image) - - Format (Sets the output format) - - Quality (The quality to set the output for jpeg files) - - Reset (Resets the image to its original loaded state) - - Resize - - Rotate (Rotate the image through 360º) - - RoundedCorners (Add rounded corners to each optional corner) - - Saturation - - Vignette (Adds a vignette effect to images) - - Watermark (Set a text watermark) - -The library consists of two binaries: **ImageProcessor.dll** and **ImageProcessor.Web.dll**. - -ImageProcessor.dll -================== - -**ImageProcessor.dll** contains all the core functionality that allows for image manipulation via the `ImageFactory` class. This has a fluent API which allows you to easily chain methods to deliver the desired output. This library contains no web specific componenets so is suitable for both desktop and web applications. - -e.g. - - // Read a file and resize it. - byte[] photoBytes = File.ReadAllBytes(file); - int quality = 70; - ImageFormat format = ImageFormat.Jpeg; - Size size = new Size(150, 0) - - using (var inStream = new MemoryStream(photoBytes)) - { - using (var outStream = new MemoryStream()) - { - using (ImageFactory imageFactory = new ImageFactory()) - { - // Load, resize, set the format and quality and save an image. - imageFactory.Load(inStream) - .Resize(size) - .Format(format) - .Quality(quality) - .Save(outStream); - } - - // Do something with the stream. - } - } - -ImageProcessor.Web.dll -====================== - -**ImageProcessor.Web.dll** contains an ASP.NET HttpModule which captures internal and external requests automagically processing them based on values captured through querystring parameters. - -Using the HttpModule requires no code writing at all. Just install the package references the binaries relevant sections in the web.config will be automatically created. - -Image requests suffixed with querystring parameters will then be processed and **cached to the server - up to 12,960,000 images** allowing for easy and efficient parsing of following requests. - -The parsing engine for the HttpModule is incredibly flexible and will **allow you to add querystring parameters in any order.** - -Installation -============ - -Installation is simple. A Nuget package for the full web version is available [here][1] and the standalone library [here][2]. - - [1]: http://nuget.org/packages/ImageProcessor.Web/ - [2]: http://nuget.org/packages/ImageProcessor/ - -Alternatively you can download and build the project and reference the binaries. Then copy the example configuration values from the demo project into your `web.config` to enable the processor. - -Usage -===== - -Heres a few examples of the syntax for processing images. - -Alpha Transparency -================== -Imageprocessor can adjust the alpha transparency of png images. Simply pass the desired percentage value (without the '%') to the processor. - -e.g. - - 60% alpha image - -Brightness -================== -Imageprocessor can adjust the brightness of images. Simply pass the desired value (-100 to 100) to the processor. - -e.g. - - 60 brightness - -Contrast -================== -Imageprocessor can adjust the contrast of images. Simply pass the desired value (-100 to 100) to the processor. - -e.g. - - 60 contrast - -Crop -==== - -Cropping an image is easy. Simply pass the top-left and bottom-right coordinates and the processor will work out the rest. - -e.g. - - your cropped image - -Filters -======= - -Everybody loves adding filter effects to photgraphs so we've baked some popular ones into Imageprocessor. - -Current filters include: - - - blackwhite - - comic (requires full trust) - - lomograph - - greyscale - - polaroid - - sepia - - gotham - - hisatch - - losatch - - invert - -e.g. - - classic polaroid look - -Flip -======= - -Imageprocessor can flip your image either horizontally or vertically. - -e.g. - - horizontal - vertical - - -Format -====== - -Imageprocessor will also allow you to change the format of image on-the-fly. This can be handy for reducing the size of requests. - -Supported file format just now are: - - - jpg - - bmp - - png - - gif (requires full trust) - -e.g. - - your image as a gif - -Quality -====== - -Whilst Imageprocessor delivers an excellent quality/filesize ratio it also allows you to change the quality of jpegs on-the-fly. - -e.g. - - your image at quality 30 - -Resize -====== - - your resized image - -Will resize your image to 200px wide whilst keeping the correct aspect ratio. - -Remote files can also be requested and cached by prefixing the src with a value set in the web.config - -e.g. - - your resized image - -Will resize your remote image to 200px wide whilst keeping the correct aspect ratio. - -Changing both width and height requires the following syntax: - - your resized image - - -Rotate -====== - -Imageprocessor can rotate your images without clipping. You can also optionally fill the background color for image types without transparency. - -e.g. - - your image rotated - your image rotated - -Saturation -================== -Imageprocessor can adjust the saturation of images. Simply pass the desired value (-100 to 100) to the processor. - -e.g. - - 60 saturation - -Vignette -====== - -Imageprocessor can also add a vignette effect to images. - -e.g. - - your image vignetted - -Watermark -========= - -Imageprocessor can add watermark text to your images with a wide range of options. Each option can be ommited and can be added in any order. Just ensure that they are pipe "|" separated: - - - text - - size (px) - - font (any installed font) - - opacity (1-100) - - style (bold|italic|regular|strikeout|underline) - - shadow - - position (x,y) - -e.g. - - watermark - -Internally it uses a class named `TextLayer` to add the watermark text. +For full documentation please see [http://jimbobsquarepants.github.io/ImageProcessor/](http://jimbobsquarepants.github.io/ImageProcessor/) From 7e1026f2457bb39bfee670374be9c9132c916b8f Mon Sep 17 00:00:00 2001 From: Chris Koiak Date: Thu, 13 Feb 2014 09:25:33 +0000 Subject: [PATCH 2/2] Added support for explicitly loaded IGraphicsProcessors Former-commit-id: ecd76b82e62ccbe743091c30bc63f30a09f5e612 --- .../NET45/Config/ImageProcessingSection.cs | 26 +++++- .../NET45/Config/ImageProcessorConfig.cs | 88 ++++++++++++------- .../config/imageprocessor/processing.config | 33 ++++--- 3 files changed, 105 insertions(+), 42 deletions(-) diff --git a/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs b/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs index ec20a7d14..c2940e3e2 100644 --- a/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs +++ b/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs @@ -71,13 +71,25 @@ namespace ImageProcessor.Web.Config set { this["name"] = value; } } + /// + /// Gets or sets the type of the plugin file. + /// + /// The full Type definition of the plugin + [ConfigurationProperty("type", DefaultValue = "", IsRequired = true)] + public string Type + { + get { return (string)this["type"]; } + + set { this["type"] = value; } + } + /// /// Gets the . /// /// /// The . /// - [ConfigurationProperty("settings", IsRequired = true)] + [ConfigurationProperty("settings", IsRequired = false)] public SettingElementCollection Settings { get @@ -114,6 +126,18 @@ namespace ImageProcessor.Web.Config get { return "plugin"; } } + /// + /// Gets or sets the autoLoadPlugins of the plugin file. + /// + /// If True plugins are auto discovered and loaded from all assemblies otherwise they must be defined in the configuration file + [ConfigurationProperty("autoLoadPlugins", DefaultValue = true, IsRequired = false)] + public bool AutoLoadPlugins + { + get { return (bool)this["autoLoadPlugins"]; } + + set { this["autoLoadPlugins"] = value; } + } + /// /// Gets or sets the /// at the specified index within the collection. diff --git a/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs b/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs index 141538767..baa524e4e 100644 --- a/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs +++ b/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs @@ -9,6 +9,8 @@ // // -------------------------------------------------------------------------------------------------------------------- +using System.Collections; + namespace ImageProcessor.Web.Config { #region Using @@ -253,49 +255,73 @@ namespace ImageProcessor.Web.Config { if (this.GraphicsProcessors == null) { - try + if (GetImageProcessingSection().Plugins.AutoLoadPlugins) { - // Build a list of native IGraphicsProcessor instances. - Type type = typeof(IGraphicsProcessor); - IEnumerable types = - AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(s => s.GetTypes()) - .Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) - .ToList(); - - // Create them and add. - this.GraphicsProcessors = - types.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList(); - - // Add the available settings. - foreach (IGraphicsProcessor processor in this.GraphicsProcessors) + try { - processor.Settings = this.GetPluginSettings(processor.GetType().Name); + // Build a list of native IGraphicsProcessor instances. + Type type = typeof (IGraphicsProcessor); + IEnumerable types = + AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(s => s.GetTypes()) + .Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) + .ToList(); + + // Create them and add. + this.GraphicsProcessors = + types.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList(); + + // Add the available settings. + foreach (IGraphicsProcessor processor in this.GraphicsProcessors) + { + processor.Settings = this.GetPluginSettings(processor.GetType().Name); + } } - } - catch (ReflectionTypeLoadException ex) - { - StringBuilder sb = new StringBuilder(); - foreach (Exception exception in ex.LoaderExceptions) + catch (ReflectionTypeLoadException ex) { - sb.AppendLine(exception.Message); - if (exception is FileNotFoundException) + StringBuilder sb = new StringBuilder(); + foreach (Exception exception in ex.LoaderExceptions) { - FileNotFoundException fileNotFoundException = exception as FileNotFoundException; - if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog)) + sb.AppendLine(exception.Message); + if (exception is FileNotFoundException) { - sb.AppendLine("Fusion Log:"); - sb.AppendLine(fileNotFoundException.FusionLog); + FileNotFoundException fileNotFoundException = exception as FileNotFoundException; + if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog)) + { + sb.AppendLine("Fusion Log:"); + sb.AppendLine(fileNotFoundException.FusionLog); + } } + + sb.AppendLine(); } - sb.AppendLine(); + string errorMessage = sb.ToString(); + + // Display or log the error based on your application. + throw new Exception(errorMessage); } + } + else + { + var pluginConfigs = imageProcessingSection.Plugins; + this.GraphicsProcessors = new List(); + foreach (ImageProcessingSection.PluginElement pluginConfig in pluginConfigs) + { + var type = Type.GetType(pluginConfig.Type); - string errorMessage = sb.ToString(); + if (type == null) + { + throw new ArgumentException("Couldn't load IGraphicsProcessor: " + pluginConfig.Type); + } + this.GraphicsProcessors.Add((Activator.CreateInstance(type) as IGraphicsProcessor)); + } - // Display or log the error based on your application. - throw new Exception(errorMessage); + // Add the available settings. + foreach (IGraphicsProcessor processor in this.GraphicsProcessors) + { + processor.Settings = this.GetPluginSettings(processor.GetType().Name); + } } } } diff --git a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config index fc33547f6..70821eeb5 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config +++ b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config @@ -1,27 +1,40 @@  - - - - - - - - + + + + + + + + + - + - + + + + + + + + + + + + +