// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
//
// The image helpers.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Helpers
{
#region Using
using System.Text.RegularExpressions;
#endregion
///
/// The image helpers.
///
public static class ImageHelpers
{
///
/// The image format regex.
///
private static readonly Regex FormatRegex = new Regex(@"(\.?)(j(pg|peg)|bmp|png|gif|ti(ff|f)|ico)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
///
/// The image format regex for matching the file format at the end of a string.
///
private static readonly Regex EndFormatRegex = new Regex(@"(\.)(j(pg|peg)|bmp|png|gif|ti(ff|f)|ico)$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
///
/// Checks a given string to check whether the value contains a valid image extension.
///
/// The string containing the filename to check.
/// True the value contains a valid image extension, otherwise false.
public static bool IsValidImageExtension(string fileName)
{
return EndFormatRegex.IsMatch(fileName);
}
///
/// Returns the correct file extension for the given string input
///
///
/// The string to parse.
///
///
/// The correct file extension for the given string input if it can find one; otherwise an empty string.
///
public static string GetExtension(string input)
{
Match match = FormatRegex.Matches(input)[0];
return match.Success ? match.Value : string.Empty;
}
}
}