Class ImageUtilities
Inherited Members
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public static class ImageUtilities
Fields
ProductImageSize
Default max size for product images (largest edge)
Declaration
public const int ProductImageSize = 2000
Field Value
Type | Description |
---|---|
int |
ThumbnailSize
Default thumbnail size
Declaration
public const int ThumbnailSize = 150
Field Value
Type | Description |
---|---|
int |
Methods
FitTo(Image, int, int)
If needed, resize the image to make it fit the given dimensions, while keeping the aspect ratio.
If you are creating thumbnails, please use the GetThumbnail(Image, int, int), which is more efficient for radical scaling of that sort.Declaration
public static Image FitTo(this Image image, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
Image | image | Source image |
int | width | Maximum width |
int | height | Maximum height |
Returns
Type | Description |
---|---|
Image | Possibly rescaled image |
GetBytes(Image)
Declaration
public static byte[] GetBytes(this Image input)
Parameters
Type | Name | Description |
---|---|---|
Image | input |
Returns
Type | Description |
---|---|
byte[] |
GetImageTypeFromBase64String(string, string)
Declaration
public static string GetImageTypeFromBase64String(string base64String, string defaultType)
Parameters
Type | Name | Description |
---|---|---|
string | base64String | |
string | defaultType |
Returns
Type | Description |
---|---|
string |
GetThumbnail(Image, int, int)
Get a thumbnail of the incoming image; the quiality of the scaling is not quite as good as for FitTo(Image, int, int), but is more efficient. Aspect ratio is maintained.
Declaration
public static Image GetThumbnail(this Image image, int width = 150, int height = 150)
Parameters
Type | Name | Description |
---|---|---|
Image | image | Source image |
int | width | Maximum width, default ThumbnailSize |
int | height | Maximum height, default ThumbnailSize |
Returns
Type | Description |
---|---|
Image | Thumbnail image |
GetThumbnail(string, int, int)
Get a thumbnail from a string-encoded image; output size is not guaranteed as short input strings will cause an immediate return in the interest of performance (a string of less than 1500 can't be a big image!)
Declaration
public static string GetThumbnail(string input, int width = 150, int height = 150)
Parameters
Type | Name | Description |
---|---|---|
string | input | Source image as base-64 encoded string |
int | width | Maximum width, default ThumbnailSize |
int | height | Maximum height, default ThumbnailSize |
Returns
Type | Description |
---|---|
string |
GetThumbnailImage(Stream, int, int)
Declaration
public static Image GetThumbnailImage(this Stream input, int width = 150, int height = 150)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | |
int | width | |
int | height |
Returns
Type | Description |
---|---|
Image |
GetThumbnailImage(string, int, int)
Get a thumbnail from a string-encoded image; output size is not guaranteed as short input strings will cause an immediate return in the interest of performance (a string of less than 1500 can't be a big image!)
Declaration
public static Image GetThumbnailImage(string input, int width = 150, int height = 150)
Parameters
Type | Name | Description |
---|---|---|
string | input | Source image as base-64 encoded string |
int | width | Maximum width, default ThumbnailSize |
int | height | Maximum height, default ThumbnailSize |
Returns
Type | Description |
---|---|
Image |
ResolveUrlOrBase64Image(string, int)
If the input is a well-formed absolute URI, then assume that it leads to an image, and fetch that image; otherwise just pass the input straight out again. Images are scaled down to 1000/1000 if needed
Declaration
public static string ResolveUrlOrBase64Image(string input, int maxPixelSize = 2000)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input, which may be a base64 encoded image or a URL |
int | maxPixelSize | Maximum image size, of longest side. Images larger than this in any direction will be shrunk (keeping the aspect ratio intact). Stretching will never occur. |
Returns
Type | Description |
---|---|
string |
Remarks
Eventually this should do some caching, have a cache-retention policy, flush etc... but in this prototype version we just fetch the data directly
ResolveUrlOrBase64ImageNoReduction(string)
If the input is a well-formed absolute URI, then assume that it leads to an image, and fetch that image; otherwise just pass the input straight out again.
Declaration
public static string ResolveUrlOrBase64ImageNoReduction(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input, which may be a base64 encoded image or a URL |
Returns
Type | Description |
---|---|
string |
Remarks
Eventually this should do some caching, have a cache-retention policy, flush etc... but in this prototype version we just fetch the data directly
TryFitImage(byte[], int, int, bool)
Declaration
public static byte[] TryFitImage(byte[] imageData, int maxWidth, int maxHeight, bool alwaysTryConvert = false)
Parameters
Type | Name | Description |
---|---|---|
byte[] | imageData | |
int | maxWidth | |
int | maxHeight | |
bool | alwaysTryConvert |
Returns
Type | Description |
---|---|
byte[] |