Class ImageHelper
Class providing methods for image processing.
public static class ImageHelper
- Inheritance
-
objectImageHelper
Fields
AUTOSIZE
Used when resizing image. (Old dimensions: x = 10, y = 20; Resizing: x = AUTOSIZE; y = 10, New dimensions: x = 5, y = 10).
public const int AUTOSIZE = -1
Field Value
- int
Properties
ImageExtensions
Image extensions supported by the system
public static HashSet<string> ImageExtensions { get; }
Property Value
- HashSet<string>
OptimizableImageExtensions
Image extensions supported by Image Optimization.
public static HashSet<string> OptimizableImageExtensions { get; }
Property Value
- HashSet<string>
UseFixedEnsureImageDimensions
Gets value that indicates if use of new image resizing is enabled.
public static bool UseFixedEnsureImageDimensions { get; }
Property Value
- bool
Methods
EnsureImageDimensions(int, int, int, int, int)
Computes new image dimensions according to the specified parameters, and returns it.
public static int[] EnsureImageDimensions(int width, int height, int maxSideSize, int imageWidth, int imageHeight)
Parameters
width
intRequired image width (optional)
height
intRequired image height (optional)
maxSideSize
intRequired max image size (overrides both required width and height, optional)
imageWidth
intImage width (required)
imageHeight
intImage height (required)
Returns
- int[]
An array with computed width ([0]) and height ([1])
Remarks
This method prevents image enlargement. Both image width and image height must be positive integers, otherwise specified image dimensions are returned. Specified image dimensions are also returned when neither width, height or maxSideSize is a positive integer.
GetAutoResizeToHeight()
Returns HEIGHT the images should be automatically resized to. Value is returned from the site settings.
public static int GetAutoResizeToHeight()
Returns
- int
GetAutoResizeToMaxSideSize()
Returns MAX SIDE SIZE the images should be automatically resized to. Value is returned from the site settings.
public static int GetAutoResizeToMaxSideSize()
Returns
- int
GetAutoResizeToWidth()
Returns WIDTH the images should be automatically resized to. Value is returned from the site settings.
public static int GetAutoResizeToWidth()
Returns
- int
GetImageDimensions(byte[])
Gets the dimensions of the provided image.
public static (int width, int height) GetImageDimensions(byte[] image)
Parameters
image
byte[]Image in binary format.
Returns
- (int width, int height)
Tuple containing width and height of the provided image.
GetImageThumbnailFileName(string, int, int)
Returns image thumbnail file name.
public static string GetImageThumbnailFileName(string guid, int width, int height)
Parameters
guid
stringFile GUID
width
intImage width
height
intImage height
Returns
- string
GetResizedImage(byte[], int, int, int, int)
Returns resized image as the data array. For quality is used DefaultQuality.
public static byte[] GetResizedImage(byte[] image, int width, int height, int originalWidth, int originalHeight)
Parameters
image
byte[]Image to be resized in binary form
width
intWidth of the resized image
height
intHeight of the resized image
originalWidth
intWidth of the original image
originalHeight
intHeight of the original image
Returns
- byte[]
GetResizedImage(byte[], string, int, int, int)
If posted file is image, resizes it to the required dimensions if possible and returns resized data. If it is not image, original data are returned.
public static byte[] GetResizedImage(byte[] fileBinary, string fileExtension, int width, int height, int maxSideSize)
Parameters
fileBinary
byte[]Posted file data
fileExtension
stringExtension of the file
width
intImage required width
height
intImage required height
maxSideSize
intImage required max side size
Returns
- byte[]
IsImage(string)
Determines whether it is an image extension or not. Accepts extensions in both formats ".gif", and "gif"
public static bool IsImage(string extension)
Parameters
extension
stringFile extension to check
Returns
- bool
IsOptimizableImage(string)
Determines whether it is an optimizable image extension or not. Accepts extensions in both formats ".jpg", and "jpg"
public static bool IsOptimizableImage(string extension)
Parameters
extension
string
Returns
- bool