Table of Contents

Class ImageHelper

Namespace
CMS.Helpers
Assembly
CMS.Helpers.dll

Class providing methods for image processing.

public static class ImageHelper
Inheritance
object
ImageHelper

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 int

Required image width (optional)

height int

Required image height (optional)

maxSideSize int

Required max image size (overrides both required width and height, optional)

imageWidth int

Image width (required)

imageHeight int

Image 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 string

File GUID

width int

Image width

height int

Image 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 int

Width of the resized image

height int

Height of the resized image

originalWidth int

Width of the original image

originalHeight int

Height 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 string

Extension of the file

width int

Image required width

height int

Image required height

maxSideSize int

Image 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 string

File 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