ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | Properties | List of all members
ImageResizer.ResizeSettings Class Reference

Represents the settings which will be used to process the image. Extends NameValueCollection to provide friendly property names for commonly used settings. Replaced by the Instructions class. Will be removed in V4.0 More...

Inheritance diagram for ImageResizer.ResizeSettings:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.ResizeSettings:
Collaboration graph
[legend]

Public Member Functions

 ResizeSettings ()
 Creates an empty settings collection. More...
 
 ResizeSettings (NameValueCollection col)
 Copies the specified collection into a new ResizeSettings instance. More...
 
 ResizeSettings (string queryString)
 Parses the specified querystring into name/value pairs. leading ? not required. Discards everything after the first '#' character as a URL fragment. More...
 
 ResizeSettings (int width, int height, FitMode mode, string imageFormat)
 Creates a new resize settings object with the specified resizing settings More...
 
bool WasOneSpecified (params string[] keys)
 Returns true if any of the specified keys are present in this NameValueCollection More...
 
RectangleF getCustomCropSourceRect (SizeF imageSize)
 
void SetDefaultImageFormat (string format)
 If 'thumbnail' and 'format' are not specified, sets 'format' to the specified value. More...
 
override string ToString ()
 Returns a string containing all the settings in the class, in querystring form. Use ToStringEncoded() to get a URL-safe querystring. This method does not encode commas, spaces, etc. More...
 
string ToStringEncoded ()
 Returns a querystring with all the settings in this class. Querystring keys and values are URL encoded properly. More...
 
void Normalize ()
 This method will 'normalize' command aliases to the primary key name and resolve duplicates. w->width, h->height, sourceFlip->sFlip, thumbnail->format More...
 
ResizeSettings Normalize (string primary, string secondary)
 Normalizes a command that has two possible names. If either of the commands has a null or empty value, those keys are removed. If both the the primary and secondary are present, the secondary is removed. Otherwise, the secondary is renamed to the primary name. More...
 

Protected Member Functions

int get (string name, int defaultValue)
 
void set (string name, int value)
 
double get (string name, double defaultValue)
 
void set (string name, double value)
 

Properties

int Width [get, set]
 ["width"]: Sets the desired width of the image. (minus padding, borders, margins, effects, and rotation). The only instance the resulting image will be smaller is if the original source image is smaller. Set Scale=Both to upscale these images and ensure the output always matches 'width' and 'height'. If both width and height are specified, the image will be 'letterboxed' to match the desired aspect ratio. Change the Mode property to adjust this behavior. More...
 
int Height [get, set]
 ["height"]: Sets the desired height of the image. (minus padding, borders, margins, effects, and rotation) The only instance the resulting image will be smaller is if the original source image is smaller. Set Scale=Both to upscale these images and ensure the output always matches 'width' and 'height'. If both width and height are specified, the image will be 'letterboxed' to match the desired aspect ratio. Change the Mode property to adjust this behavior. More...
 
int MaxWidth [get, set]
 ["maxwidth"]: Sets the maximum desired width of the image. (minus padding, borders, margins, effects, and rotation). The image may be smaller than this value to maintain aspect ratio when both maxwidth and maxheight are specified. More...
 
int Quality [get, set]
 ["quality"]: The jpeg encoding quality to use. (10..100). 90 is the default and best value, you should leave it. More...
 
int MaxHeight [get, set]
 ["maxheight"]: Sets the maximum desired height of the image. (minus padding, borders, margins, effects, and rotation). The image may be smaller than this value to maintain aspect ratio when both maxwidth and maxheight are specified. More...
 
FitMode Mode [get, set]
 ["mode"]: Sets the fit mode for the image. max, min, pad, crop, carve, stretch More...
 
double Rotate [get, set]
 ["rotate"] The degress to rotate the image clockwise. -360 to 360. More...
 
ContentAlignment Anchor [get, set]
 How to anchor the image when cropping or adding whitespace to meet sizing requirements. More...
 
RotateFlipType Flip [get, set]
 Allows you to flip the entire resulting image vertically, horizontally, or both. Rotation is not supported. More...
 
RotateFlipType SourceFlip [get, set]
 ["sFlip"] Allows you to flip the source image vertically, horizontally, or both. Rotation is not supported. More...
 
ScaleMode Scale [get, set]
 ["scale"] Whether to downscale, upscale, upscale the canvas, or both upscale or downscale the image as needed. Defaults to DownscaleOnly. See the DefaultSettings plugin to adjust the default. More...
 
StretchMode Stretch [get, set]
 [Deprecated] (Replaced by mode=stretch) Whether to preserve aspect ratio or stretch to fill the bounds. More...
 
ServerCacheMode Cache [get, set]
 ["cache"]: Server caching mode suggestion for the result More...
 
ProcessWhen Process [get, set]
 ["process"]: Server processing suggestion for the result. Allows you to 'disable' processing of the image (so you can use disk caching with non-image files). Allows you to 'force' processing of the image, for images without a querystring. More...
 
CropMode CropMode [get, set]
 ["crop"]=none|auto Defaults to None - letterboxing is used if both width and height are supplied, and stretch = proportionally. Set CropTopLeft and CropBottomRight when you need to specify a custom crop rectangle. More...
 
double[] CropValues [get, set]
 4 values specify x1,y1,x2,y2 values for the crop rectangle. Negative values are relative to the bottom right - on a 100x100 picture, (10,10,90,90) is equivalent to (10,10,-10,-10). And (0,0,0,0) is equivalent to (0,0,100,100). More...
 
PointF CropTopLeft [get, set]
 ["crop"]=([x1],[y1],x2,y2). Sets x1 and y21, the top-right corner of the crop rectangle. If 0 or greater, the coordinate is relative to the top-left corner of the image. If less than 0, the value is relative to the bottom-right corner. This allows for easy trimming: crop=(10,10,-10,-10). Set ["cropxunits"] and ["cropyunits"] to the width/height of the rectangle your coordinates are relative to, if different from the original image size. More...
 
PointF CropBottomRight [get, set]
 ["crop"]=(x1,y1,[x2],[y2]). Sets x2 and y2, the bottom-right corner of the crop rectangle. If 1 or greater, the coordinate is relative to the top-left corner of the image. If 0 or less, the value is relative to the bottom-right corner. This allows for easy trimming: crop=(10,10,-10,-10). Set ["cropxunits"] and ["cropyunits"] to the width/height of the rectangle your coordinates are relative to, if different from the original image size. More...
 
Color BackgroundColor [get, set]
 ["bgcolor"]: Named and hex values are supported. (rgb and rgba, both 3, 6, and 8 digits). More...
 
Color PaddingColor [get, set]
 Gets/sets ["paddingColor"]. Named and hex values are supported. (rgb and rgba, both 3, 6, and 8 digits). More...
 
BoxPadding Padding [get, set]
 ["paddingWidth"]: Gets/sets the width(s) of padding inside the image border. More...
 
BoxPadding Margin [get, set]
 ["margin"]: Gets/sets the width(s) of the margin outside the image border and effects. More...
 
Color BorderColor [get, set]
 Gets/sets ["borderColor"]. Named and hex values are supported. (rgb and rgba, both 3, 6, and 8 digits). More...
 
BoxPadding Border [get, set]
 Friendly get/set accessor for the ["borderWidth"] value. Returns BoxPadding.Empty when unspecified. More...
 
string Format [get, set]
 Like this["format"]. Gets or sets the output file format to use. "png", "jpg", and "gif" are valid values. Returns null if unspecified. When format is not specified, the original format of the image is used (unless it is not a web safe format - jpeg is the fallback in that scenario). More...
 
double CropXUnits [get, set]
 The width which the X and X2 crop values should be applied. For example, a value of '100' makes X and X2 percentages of the original image width. This can be set to any non-negative value. Very useful for performing cropping when the original image size is unknown. 0 indicates that the crop values are relative to the original size of the image. More...
 
double CropYUnits [get, set]
 The width which the Y and Y2 crop values should be applied. For example, a value of '100' makes Y and Y2 percentages of the original image height. This can be set to any non-negative value. Very useful for performing cropping when the original image size is unknown. 0 indicates that the crop values are relative to the original size of the image. More...
 

Detailed Description

Represents the settings which will be used to process the image. Extends NameValueCollection to provide friendly property names for commonly used settings. Replaced by the Instructions class. Will be removed in V4.0

Definition at line 20 of file ResizeSettings.cs.

Constructor & Destructor Documentation

ImageResizer.ResizeSettings.ResizeSettings ( )
inline

Creates an empty settings collection.

Definition at line 25 of file ResizeSettings.cs.

25 : base() { }
ImageResizer.ResizeSettings.ResizeSettings ( NameValueCollection  col)
inline

Copies the specified collection into a new ResizeSettings instance.

Parameters
col

Definition at line 30 of file ResizeSettings.cs.

30 : base(col) { }
ImageResizer.ResizeSettings.ResizeSettings ( string  queryString)
inline

Parses the specified querystring into name/value pairs. leading ? not required. Discards everything after the first '#' character as a URL fragment.

Parameters
queryString

Definition at line 36 of file ResizeSettings.cs.

A set of utility methods for manipulating virtual paths
Definition: PathUtils.cs:17
static NameValueCollection ParseQueryStringFriendlyAllowSemicolons(string path)
Like ParseQueryString, but permits the leading '?' to be omitted, and semicolons can be substituted f...
Definition: PathUtils.cs:322
ImageResizer.ResizeSettings.ResizeSettings ( int  width,
int  height,
FitMode  mode,
string  imageFormat 
)
inline

Creates a new resize settings object with the specified resizing settings

Parameters
width
height
mode
imageFormatThe desired image format, like 'jpg', 'gif', or 'png'. Leave null if you want to preserve the original format.

Definition at line 45 of file ResizeSettings.cs.

45  {
46  this.Width = width;
47  this.Height = height;
48  this.Mode = mode;
49  if (imageFormat != null) this.Format = imageFormat;
50  }

Member Function Documentation

void ImageResizer.ResizeSettings.Normalize ( )
inline

This method will 'normalize' command aliases to the primary key name and resolve duplicates. w->width, h->height, sourceFlip->sFlip, thumbnail->format

Definition at line 398 of file ResizeSettings.cs.

398  {
399  this.Normalize("width", "w")
400  .Normalize("height", "h")
401  .Normalize("sFlip", "sourceFlip")
402  .Normalize("format", "thumbnail");
403  }
void Normalize()
This method will 'normalize' command aliases to the primary key name and resolve duplicates. w->width, h->height, sourceFlip->sFlip, thumbnail->format
ResizeSettings ImageResizer.ResizeSettings.Normalize ( string  primary,
string  secondary 
)
inline

Normalizes a command that has two possible names. If either of the commands has a null or empty value, those keys are removed. If both the the primary and secondary are present, the secondary is removed. Otherwise, the secondary is renamed to the primary name.

Parameters
primary
secondary

Definition at line 415 of file ResizeSettings.cs.

415  {
416  return (ResizeSettings)NameValueCollectionExtensions.Normalize(this, primary, secondary);
417  }
ResizeSettings()
Creates an empty settings collection.
void ImageResizer.ResizeSettings.SetDefaultImageFormat ( string  format)
inline

If 'thumbnail' and 'format' are not specified, sets 'format' to the specified value.

Parameters
format

Definition at line 374 of file ResizeSettings.cs.

374  {
375  if (string.IsNullOrEmpty(this["thumbnail"]) && string.IsNullOrEmpty(this["format"])) this["format"] = format;
376  }
override string ImageResizer.ResizeSettings.ToString ( )
inline

Returns a string containing all the settings in the class, in querystring form. Use ToStringEncoded() to get a URL-safe querystring. This method does not encode commas, spaces, etc.

Returns

Definition at line 383 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.Watermark.ImageLayer.GetMemCachedBitmap().

383  {
384  return PathUtils.BuildQueryString(this,false);
385  }
string ImageResizer.ResizeSettings.ToStringEncoded ( )
inline

Returns a querystring with all the settings in this class. Querystring keys and values are URL encoded properly.

Returns

Definition at line 390 of file ResizeSettings.cs.

390  {
391  return PathUtils.BuildQueryString(this);
392  }
bool ImageResizer.ResizeSettings.WasOneSpecified ( params string[]  keys)
inline

Returns true if any of the specified keys are present in this NameValueCollection

Parameters
keys
Returns

Definition at line 132 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.SimpleFilters.SimpleFilters.PostCreateImageAttributes(), and ImageResizer.Plugins.AdvancedFilters.AdvancedFilters.PreRenderImage().

132  {
133  return NameValueCollectionExtensions.IsOneSpecified(this, keys);
134  }

Property Documentation

ContentAlignment ImageResizer.ResizeSettings.Anchor
getset

How to anchor the image when cropping or adding whitespace to meet sizing requirements.

Definition at line 146 of file ResizeSettings.cs.

Color ImageResizer.ResizeSettings.BackgroundColor
getset

["bgcolor"]: Named and hex values are supported. (rgb and rgba, both 3, 6, and 8 digits).

Definition at line 278 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.FreeImageBuilder.FreeImageBuilderPlugin.buildFiBitmap(), and ImageResizer.ImageBuilder.RenderPadding().

BoxPadding ImageResizer.ResizeSettings.Border
getset

Friendly get/set accessor for the ["borderWidth"] value. Returns BoxPadding.Empty when unspecified.

Definition at line 322 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutBorder(), and ImageResizer.ImageBuilder.RenderBorder().

Color ImageResizer.ResizeSettings.BorderColor
getset

Gets/sets ["borderColor"]. Named and hex values are supported. (rgb and rgba, both 3, 6, and 8 digits).

Definition at line 315 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.RenderBorder().

ServerCacheMode ImageResizer.ResizeSettings.Cache
getset

["cache"]: Server caching mode suggestion for the result

Definition at line 196 of file ResizeSettings.cs.

PointF ImageResizer.ResizeSettings.CropBottomRight
getset

["crop"]=(x1,y1,[x2],[y2]). Sets x2 and y2, the bottom-right corner of the crop rectangle. If 1 or greater, the coordinate is relative to the top-left corner of the image. If 0 or less, the value is relative to the bottom-right corner. This allows for easy trimming: crop=(10,10,-10,-10). Set ["cropxunits"] and ["cropyunits"] to the width/height of the rectangle your coordinates are relative to, if different from the original image size.

Definition at line 266 of file ResizeSettings.cs.

CropMode ImageResizer.ResizeSettings.CropMode
getset

["crop"]=none|auto Defaults to None - letterboxing is used if both width and height are supplied, and stretch = proportionally. Set CropTopLeft and CropBottomRight when you need to specify a custom crop rectangle.

Definition at line 222 of file ResizeSettings.cs.

PointF ImageResizer.ResizeSettings.CropTopLeft
getset

["crop"]=([x1],[y1],x2,y2). Sets x1 and y21, the top-right corner of the crop rectangle. If 0 or greater, the coordinate is relative to the top-left corner of the image. If less than 0, the value is relative to the bottom-right corner. This allows for easy trimming: crop=(10,10,-10,-10). Set ["cropxunits"] and ["cropyunits"] to the width/height of the rectangle your coordinates are relative to, if different from the original image size.

Definition at line 252 of file ResizeSettings.cs.

double [] ImageResizer.ResizeSettings.CropValues
getsetprotected

4 values specify x1,y1,x2,y2 values for the crop rectangle. Negative values are relative to the bottom right - on a 100x100 picture, (10,10,90,90) is equivalent to (10,10,-10,-10). And (0,0,0,0) is equivalent to (0,0,100,100).

Definition at line 236 of file ResizeSettings.cs.

double ImageResizer.ResizeSettings.CropXUnits
getset

The width which the X and X2 crop values should be applied. For example, a value of '100' makes X and X2 percentages of the original image width. This can be set to any non-negative value. Very useful for performing cropping when the original image size is unknown. 0 indicates that the crop values are relative to the original size of the image.

Definition at line 354 of file ResizeSettings.cs.

double ImageResizer.ResizeSettings.CropYUnits
getset

The width which the Y and Y2 crop values should be applied. For example, a value of '100' makes Y and Y2 percentages of the original image height. This can be set to any non-negative value. Very useful for performing cropping when the original image size is unknown. 0 indicates that the crop values are relative to the original size of the image.

Definition at line 360 of file ResizeSettings.cs.

RotateFlipType ImageResizer.ResizeSettings.Flip
getset

Allows you to flip the entire resulting image vertically, horizontally, or both. Rotation is not supported.

Definition at line 155 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.ProcessFinalBitmap().

string ImageResizer.ResizeSettings.Format
getset

Like this["format"]. Gets or sets the output file format to use. "png", "jpg", and "gif" are valid values. Returns null if unspecified. When format is not specified, the original format of the image is used (unless it is not a web safe format - jpeg is the fallback in that scenario).

Also checks the 'thumbnail' value for V2 compatibility. When set, 'thumnail' is removed and only 'format' is used.

Definition at line 338 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.WebPEncoder.WebPEncoderPlugin.CreateIfSuitable(), and ImageResizer.Plugins.Basic.DefaultEncoder.CreateIfSuitable().

int ImageResizer.ResizeSettings.Height
getset

["height"]: Sets the desired height of the image. (minus padding, borders, margins, effects, and rotation) The only instance the resulting image will be smaller is if the original source image is smaller. Set Scale=Both to upscale these images and ensure the output always matches 'width' and 'height'. If both width and height are specified, the image will be 'letterboxed' to match the desired aspect ratio. Change the Mode property to adjust this behavior.

Definition at line 79 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.PdfRenderer.PdfRendererPlugin.DecodeStream(), ImageResizer.Plugins.CropAround.CropAroundPlugin.LayoutImage(), and ImageResizer.ImageBuilder.LayoutImage().

BoxPadding ImageResizer.ResizeSettings.Margin
getset

["margin"]: Gets/sets the width(s) of the margin outside the image border and effects.

Definition at line 304 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutMargin().

int ImageResizer.ResizeSettings.MaxHeight
getset

["maxheight"]: Sets the maximum desired height of the image. (minus padding, borders, margins, effects, and rotation). The image may be smaller than this value to maintain aspect ratio when both maxwidth and maxheight are specified.

Definition at line 111 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutImage().

int ImageResizer.ResizeSettings.MaxWidth
getset

["maxwidth"]: Sets the maximum desired width of the image. (minus padding, borders, margins, effects, and rotation). The image may be smaller than this value to maintain aspect ratio when both maxwidth and maxheight are specified.

Definition at line 89 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutImage().

FitMode ImageResizer.ResizeSettings.Mode
getset

["mode"]: Sets the fit mode for the image. max, min, pad, crop, carve, stretch

Definition at line 118 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.CropAround.CropAroundPlugin.LayoutImage(), and ImageResizer.Plugins.Basic.DefaultSettings.Modify().

BoxPadding ImageResizer.ResizeSettings.Padding
getset

["paddingWidth"]: Gets/sets the width(s) of padding inside the image border.

Definition at line 293 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutPadding().

Color ImageResizer.ResizeSettings.PaddingColor
getset

Gets/sets ["paddingColor"]. Named and hex values are supported. (rgb and rgba, both 3, 6, and 8 digits).

Definition at line 286 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.RenderPadding().

ProcessWhen ImageResizer.ResizeSettings.Process
getset

["process"]: Server processing suggestion for the result. Allows you to 'disable' processing of the image (so you can use disk caching with non-image files). Allows you to 'force' processing of the image, for images without a querystring.

Definition at line 208 of file ResizeSettings.cs.

int ImageResizer.ResizeSettings.Quality
getset

["quality"]: The jpeg encoding quality to use. (10..100). 90 is the default and best value, you should leave it.

Definition at line 97 of file ResizeSettings.cs.

double ImageResizer.ResizeSettings.Rotate
getset

["rotate"] The degress to rotate the image clockwise. -360 to 360.

Definition at line 138 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutRotate().

ScaleMode ImageResizer.ResizeSettings.Scale
getset

["scale"] Whether to downscale, upscale, upscale the canvas, or both upscale or downscale the image as needed. Defaults to DownscaleOnly. See the DefaultSettings plugin to adjust the default.

Definition at line 176 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.LayoutImage().

RotateFlipType ImageResizer.ResizeSettings.SourceFlip
getset

["sFlip"] Allows you to flip the source image vertically, horizontally, or both. Rotation is not supported.

Definition at line 164 of file ResizeSettings.cs.

Referenced by ImageResizer.ImageBuilder.PrepareSourceBitmap().

StretchMode ImageResizer.ResizeSettings.Stretch
getset

[Deprecated] (Replaced by mode=stretch) Whether to preserve aspect ratio or stretch to fill the bounds.

Definition at line 186 of file ResizeSettings.cs.

int ImageResizer.ResizeSettings.Width
getset

["width"]: Sets the desired width of the image. (minus padding, borders, margins, effects, and rotation). The only instance the resulting image will be smaller is if the original source image is smaller. Set Scale=Both to upscale these images and ensure the output always matches 'width' and 'height'. If both width and height are specified, the image will be 'letterboxed' to match the desired aspect ratio. Change the Mode property to adjust this behavior.

Definition at line 66 of file ResizeSettings.cs.

Referenced by ImageResizer.Plugins.PdfRenderer.PdfRendererPlugin.DecodeStream(), ImageResizer.Plugins.CropAround.CropAroundPlugin.LayoutImage(), and ImageResizer.ImageBuilder.LayoutImage().


The documentation for this class was generated from the following file: