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.
[Obsolete("Method is obsolete and will be removed in future versions.")]
public static int[] EnsureImageDimensions(int width, int height, int maxSideSize, int imageWidth, int imageHeight)
Parameters
widthintRequired image width (optional)
heightintRequired image height (optional)
maxSideSizeintRequired max image size (overrides both required width and height, optional)
imageWidthintImage width (required)
imageHeightintImage 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.
[Obsolete("Method is obsolete and will be removed in future versions.")]
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.
[Obsolete("Method is obsolete and will be removed in future versions.")]
public static int GetAutoResizeToMaxSideSize()
Returns
- int
GetAutoResizeToWidth()
Returns WIDTH the images should be automatically resized to. Value is returned from the site settings.
[Obsolete("Method is obsolete and will be removed in future versions.")]
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
imagebyte[]Image in binary format.
Returns
- (int imageWidth, int imageHeight)
Tuple containing width and height of the provided image.
GetImageThumbnailFileName(string, int, int)
Returns image thumbnail file name.
[Obsolete("Method is obsolete and will be removed in future versions.")]
public static string GetImageThumbnailFileName(string guid, int width, int height)
Parameters
guidstringFile GUID
widthintImage width
heightintImage height
Returns
- string
GetResizedImage(byte[], int, int, int, int)
Returns resized image as the data array. For quality is used DefaultQuality.
[Obsolete("Method is obsolete and will be removed in future versions.")]
public static byte[] GetResizedImage(byte[] image, int width, int height, int originalWidth, int originalHeight)
Parameters
imagebyte[]Image to be resized in binary form
widthintWidth of the resized image
heightintHeight of the resized image
originalWidthintWidth of the original image
originalHeightintHeight 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
fileBinarybyte[]Posted file data
fileExtensionstringExtension of the file
widthintImage required width
heightintImage required height
maxSideSizeintImage 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
extensionstringFile 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
extensionstring
Returns
- bool