mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: c2f8940d3852b524b66a9c1a402adc155c5efe2b Former-commit-id: 5cc3f548c68cf825f0b04fbb14eb9e67529c9bddpull/17/head
14 changed files with 371 additions and 289 deletions
@ -0,0 +1,106 @@ |
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
// <copyright file="RotateBounded.cs" company="James South">
|
|||
// Copyright (c) James South.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
// <summary>
|
|||
// Encapsulates methods to rotate an image without expanding the canvas.
|
|||
// </summary>
|
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessor.Web.Processors |
|||
{ |
|||
using System; |
|||
using System.Text.RegularExpressions; |
|||
using ImageProcessor.Processors; |
|||
using ImageProcessor.Web.Helpers; |
|||
|
|||
/// <summary>
|
|||
/// Encapsulates methods to rotate an image without expanding the canvas.
|
|||
/// </summary>
|
|||
public class RotateBounded : IWebGraphicsProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// The regular expression to search strings for.
|
|||
/// </summary>
|
|||
private static readonly Regex QueryRegex = new Regex(@"rotatebounded=[^&]+", RegexOptions.Compiled); |
|||
|
|||
/// <summary>
|
|||
/// The regular expression to search for.
|
|||
/// </summary>
|
|||
private static readonly Regex BoundRegex = new Regex(@"rotatebounded.keepsize=true", RegexOptions.Compiled); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RotateBounded"/> class.
|
|||
/// </summary>
|
|||
public RotateBounded() |
|||
{ |
|||
this.Processor = new ImageProcessor.Processors.RotateBounded(); |
|||
} |
|||
|
|||
#region IGraphicsProcessor Members
|
|||
/// <summary>
|
|||
/// Gets the regular expression to search strings for.
|
|||
/// </summary>
|
|||
public Regex RegexPattern |
|||
{ |
|||
get |
|||
{ |
|||
return QueryRegex; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the order in which this processor is to be used in a chain.
|
|||
/// </summary>
|
|||
public int SortOrder |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the associated graphics processor.
|
|||
/// </summary>
|
|||
public IGraphicsProcessor Processor { get; private set; } |
|||
|
|||
/// <summary>
|
|||
/// The position in the original string where the first character of the captured substring was found.
|
|||
/// </summary>
|
|||
/// <param name="queryString">
|
|||
/// The query string to search.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The zero-based starting position in the original string where the captured substring was found.
|
|||
/// </returns>
|
|||
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; |
|||
float angle = CommonParameterParserUtility.ParseAngle(match.Value); |
|||
bool keepSize = BoundRegex.Match(queryString).Success; |
|||
Tuple<float, bool> rotateParams = new Tuple<float, bool>(angle, keepSize); |
|||
|
|||
this.Processor.DynamicParameter = rotateParams; |
|||
} |
|||
|
|||
index += 1; |
|||
} |
|||
} |
|||
|
|||
return this.SortOrder; |
|||
} |
|||
#endregion
|
|||
} |
|||
} |
|||
@ -1,30 +0,0 @@ |
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
// <copyright file="ImageLayer.cs" company="James South">
|
|||
// Copyright (c) James South.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
// <summary>
|
|||
// Encapsulates the properties required to add an rotation layer to an image.
|
|||
// </summary>
|
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessor.Imaging |
|||
{ |
|||
/// <summary>
|
|||
/// A rotation layer to apply an inside rotation to an image
|
|||
/// </summary>
|
|||
public class RotateInsideLayer |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the rotation angle.
|
|||
/// </summary>
|
|||
public float Angle { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a value indicating whether to keep the image dimensions.
|
|||
/// If set to true, the image is zoomed inside the area.
|
|||
/// If set to false, the area is resized to match the rotated image.
|
|||
/// </summary>
|
|||
public bool KeepImageDimensions { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue