// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // // // Flips an image horizontally or vertically. // // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Web.Processors { using System.Drawing; using System.Text.RegularExpressions; using ImageProcessor.Processors; /// /// Flips an image horizontally or vertically. /// public class Flip : IWebGraphicsProcessor { /// /// The regular expression to search strings for. /// private static readonly Regex QueryRegex = new Regex(@"flip=(horizontal|vertical|both)", RegexOptions.Compiled); /// /// Initializes a new instance of the class. /// public Flip() { this.Processor = new ImageProcessor.Processors.Flip(); } /// /// Gets the regular expression to search strings for. /// public Regex RegexPattern { get { return QueryRegex; } } /// /// Gets the order in which this processor is to be used in a chain. /// public int SortOrder { get; private set; } /// /// Gets the associated graphics processor. /// public IGraphicsProcessor Processor { get; private set; } /// /// The position in the original string where the first character of the captured substring was found. /// /// /// The query string to search. /// /// /// The zero-based starting position in the original string where the captured substring was found. /// public int MatchRegexIndex(string queryString) { int index = 0; // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; foreach (Match match in this.RegexPattern.Matches(queryString)) { if (match.Success) { if (index == 0) { // Set the index on the first instance only. this.SortOrder = match.Index; string direction = match.Value.Split('=')[1]; switch (direction) { case "horizontal": this.Processor.DynamicParameter = RotateFlipType.RotateNoneFlipX; break; case "vertical": this.Processor.DynamicParameter = RotateFlipType.RotateNoneFlipY; break; default: this.Processor.DynamicParameter = RotateFlipType.RotateNoneFlipXY; break; } } index += 1; } } return this.SortOrder; } } }