ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Types | Public Member Functions | Properties | List of all members
ImageResizer.Plugins.Watermark.Layer Class Reference
Inheritance diagram for ImageResizer.Plugins.Watermark.Layer:
Inheritance graph
[legend]

Public Types

enum  LayerPlacement { Overlay, Background }
 

Public Member Functions

 Layer (NameValueCollection settings)
 
virtual void CopyTo (Layer other)
 
virtual object[] GetHashBasis ()
 
int GetDataHash ()
 
delegate Size CalculateLayerContentSize (double maxwidth, double maxheight)
 
RectangleF CalculateLayerCoordinates (ImageState s, CalculateLayerContentSize actualSizeCalculator, bool forceInsideCanvas)
 Returns a rectangle with canvas-relative coordinates. A callback is required to calculate the actual size of the content based on the specified bounds. The callback may be passed double.NaN for one or more paramters to indicate that they are not specified. More...
 
double Resolve (DistanceUnit value, double relativeToValue, double percentRelativeTo, bool invert)
 
virtual void RenderTo (ImageState s)
 

Properties

DistanceUnit Top [get, set]
 The offset from the top of the container. Percentages are relative to the container height. Defines the upper boundary for the layer. If null, Bottom will be used to calcuate the value based on the height. If Bottom is not specified, defaults to 0. Positive values are inside the container, negative values outside it. More...
 
DistanceUnit Left [get, set]
 The offset from the left of the container. Percentages are relative to the container width. Defines the leftmost boundary for the layer. If null, Right will be used to calcuate the value based on the width. If Right is not specified, defaults to 0. Positive values are inside the container, negative values outside it. More...
 
DistanceUnit Right [get, set]
 The offset relative to the right side of the container. Percentages are relative to the container width. Defines the rightmost boundary for the layer. If null, Top will be used to calcuate the value based on the height. If Top is not specified, defaults to 0. Positive values are inside the container, negative values outside it. More...
 
DistanceUnit Bottom [get, set]
 The offset relative to the bottom of the container. Percentages are relative to the container height. Defines the bottom-most boundary for the layer. If null, Top will be used to calcuate the value based on the height. If Top is not specified, defaults to 0. Positive values are inside the container, negative values outside it. More...
 
DistanceUnit Width [get, set]
 The width of the layer. If used with both Left and Right, the smaller result wins. I.e, with a 100px container, width=50, left=30, right=30, the resulting width will be 40. If null, Left and Right will be used to calcuate the value. If both Left and Right are not specified, the natural width of the layer's contents will be used. Percentages are relative to the container width. More...
 
DistanceUnit Height [get, set]
 The height of the layer. If used with both Top and Bottom, the smaller result wins. I.e, with a 100px container, height=50, top=30, top=30, the resulting height will be 40. If null, Top and Bottom will be used to calcuate the value. If both Top and Bottom are not specified, the natural height of the layer's contents will be used. Percentages are relative to the container height. More...
 
string RelativeTo [get, set]
 Specifies the container that the position values (top,left,right,bottom,width,heght) are relative to. The default is 'image' (the innermost square, which contains the original photo). Additional valid values include 'imageArea' (includes whitespace added to preserve aspect ratio), 'padding', 'border', 'margin', and 'canvas'. More...
 
ContentAlignment Align [get, set]
 The alignment to use when (a) all 3 horizontal or vertical values are specified, and they need to be resolved, (b) when only width/height are specified, (c) when no positioning values are specified, or (d) when the content doesn't precisely fill they layer bounds. More...
 
bool Fill [get, set]
 (defaults false). When true, the image or text will attempt to fill 1 of the layer's bounds, even if upscaling is required. When Width is not specified, and both left and right are not specififed, this causes the image to fill the container width (if possible). When Height is not specified, and both top and bottom are not specififed, this causes the image to fill the container height (if possible). This causes &scale=both to be used on images unless another setting is specified in imageQuery. More...
 
LayerPlacement DrawAs [get, set]
 The z-order at which to draw the layer. Curret options are Overlay (over everything) and Background (over the background color). More...
 

Detailed Description

Definition at line 11 of file Layer.cs.

Member Function Documentation

RectangleF ImageResizer.Plugins.Watermark.Layer.CalculateLayerCoordinates ( ImageState  s,
CalculateLayerContentSize  actualSizeCalculator,
bool  forceInsideCanvas 
)
inline

Returns a rectangle with canvas-relative coordinates. A callback is required to calculate the actual size of the content based on the specified bounds. The callback may be passed double.NaN for one or more paramters to indicate that they are not specified.

Parameters
s
Returns

Definition at line 184 of file Layer.cs.

184  {
185  //Find container
186  RectangleF cont;
187  if (s.layout.ContainsRing(RelativeTo))
189  else if ("canvas".Equals(RelativeTo, StringComparison.OrdinalIgnoreCase))
190  cont = new RectangleF(new PointF(), s.destSize);
191  else
192  cont = PolygonMath.GetBoundingBox(s.layout["image"]);
193 
194  //Calculate layer coords
195  RectangleF rect = new RectangleF();
196 
197  //Resolve all values to the same coordinate plane, null values will be transformed to NaN
198  double left = Resolve(Left, cont.X, cont.Width, false);
199  double top = Resolve(Top, cont.Y, cont.Height, false);
200  double right = Resolve(Right, cont.Right, cont.Width, true);
201  double bottom = Resolve(Bottom, cont.Bottom, cont.Height, true);
202  double width = Resolve(Width, 0, cont.Width, false);
203  double height = Resolve(Height, 0, cont.Height, false);
204 
205  //Force all values to be within the canvas area.
206  if (forceInsideCanvas) {
207  SizeF canvas = s.destSize;
208  if (!double.IsNaN(left)) left = Math.Min(Math.Max(0, left), canvas.Width);
209  if (!double.IsNaN(right)) right = Math.Min(Math.Max(0, right), canvas.Width);
210  if (!double.IsNaN(width)) width = Math.Min(Math.Max(0, width), canvas.Width);
211  if (!double.IsNaN(bottom)) bottom = Math.Min(Math.Max(0, bottom), canvas.Height);
212  if (!double.IsNaN(top)) top = Math.Min(Math.Max(0, top), canvas.Height);
213  if (!double.IsNaN(height)) height = Math.Min(Math.Max(0, height), canvas.Height);
214  }
215 
216  //If right and left (or top and bottom) are inverted, avg them and set them equal.
217  if (!double.IsNaN(left) && !double.IsNaN(right) && right < left) left = right = ((left + right) / 2);
218  if (!double.IsNaN(top) && !double.IsNaN(bottom) && bottom < top) bottom = top = ((bottom + top) / 2);
219 
220 
221  //Fill in width/height if enough stuff is specified
222  if (!double.IsNaN(left) && !double.IsNaN(right) && double.IsNaN(width)) width = Math.Max(right - left,0);
223  if (!double.IsNaN(top) && !double.IsNaN(bottom) && double.IsNaN(height)) height = Math.Max(bottom - top,0);
224 
225 
226  //Execute the callback to get the actual size. Update the width and height values if the actual size is smaller.
227  SizeF normalSize = actualSizeCalculator((double.IsNaN(width) && Fill) ? cont.Width : width, (double.IsNaN(height) && Fill) ? cont.Height : height);
228  if (double.IsNaN(width) || width > normalSize.Width) width = normalSize.Width;
229  if (double.IsNaN(height) || height > normalSize.Height) height = normalSize.Height;
230 
231 
232 
233  //If only width and height are specified, set the other values to match the container, and let alignment sort it out.
234  if (double.IsNaN(left) && double.IsNaN(right)) { left = cont.X; right = cont.Right; }//Handle situations where neither left nor right is specified, pretend left=0
235  if (double.IsNaN(top) && double.IsNaN(bottom)) { top = cont.X; bottom = cont.Bottom; } //Handle situations where neither top nor bottom is specified, pretend top=0
236 
237 
238  //When all 3 values are specified in either direction, we must use the alignment setting to determine which direction to snap to.
239  if (!double.IsNaN(left) && !double.IsNaN(right) && !double.IsNaN(width)) {
240  if (width > right - left) width = right - left; //Use the smaller value in this case, no need to align.
241  else {
242  if (Align == ContentAlignment.BottomLeft || Align == ContentAlignment.MiddleLeft || Align == ContentAlignment.TopLeft)
243  right = left + width;
244  if (Align == ContentAlignment.BottomCenter || Align == ContentAlignment.MiddleCenter || Align == ContentAlignment.TopCenter){
245  left += (right-left-width) /2;
246  right = left + width;
247  }
248  if (Align == ContentAlignment.BottomRight || Align == ContentAlignment.MiddleRight || Align == ContentAlignment.TopRight)
249  left = right - width;
250  }
251  }
252 
253  //When all 3 values are specified in either direction, we must use the alignment setting to determine which direction to snap to.
254  if (!double.IsNaN(top) && !double.IsNaN(bottom) && !double.IsNaN(height)) {
255  if (height > bottom - top) height = bottom - top; //Use the smaller value in this case, no need to align.
256  else {
257  if (Align == ContentAlignment.TopLeft || Align == ContentAlignment.TopCenter || Align == ContentAlignment.TopRight)
258  bottom = top + height;
259  if (Align == ContentAlignment.MiddleLeft || Align == ContentAlignment.MiddleCenter || Align == ContentAlignment.MiddleRight) {
260  top += (bottom - top - height) / 2;
261  bottom = top + height;
262  }
263  if (Align == ContentAlignment.BottomLeft || Align == ContentAlignment.BottomCenter || Align == ContentAlignment.BottomRight)
264  top = bottom - height;
265  }
266  }
267 
268 
269  //Calculate values for top and left based off bottom and right
270  if (double.IsNaN(left)) left = right - width;
271  if (double.IsNaN(top)) top = bottom - height;
272 
273  //Calculate values for bottom and right based off top and left
274  if (double.IsNaN(right)) right = left + width;
275  if (double.IsNaN(bottom)) bottom = top + height;
276 
277 
278  return new RectangleF((float)left, (float)top, (float)width, (float)height);
279 
280  }
bool Fill
(defaults false). When true, the image or text will attempt to fill 1 of the layer&#39;s bounds...
Definition: Layer.cs:159
DistanceUnit Left
The offset from the left of the container. Percentages are relative to the container width...
Definition: Layer.cs:75
DistanceUnit Height
The height of the layer. If used with both Top and Bottom, the smaller result wins. I.e, with a 100px container, height=50, top=30, top=30, the resulting height will be 40. If null, Top and Bottom will be used to calcuate the value. If both Top and Bottom are not specified, the natural height of the layer&#39;s contents will be used. Percentages are relative to the container height.
Definition: Layer.cs:118
ContentAlignment Align
The alignment to use when (a) all 3 horizontal or vertical values are specified, and they need to be ...
Definition: Layer.cs:146
Size destSize
The size of the target bitmap image. Set after all sizing operations have completed.
Definition: ImageState.cs:47
Defines a collection of utility functions for manipulating polygons. These functions may be (re)moved...
Definition: PolygonMath.cs:13
static RectangleF GetBoundingBox(PointF[] points)
Returns a bounding box for the specified set of points.
Definition: PolygonMath.cs:218
DistanceUnit Bottom
The offset relative to the bottom of the container. Percentages are relative to the container height...
Definition: Layer.cs:97
LayoutBuilder layout
The layout object. Used for calculated and flowing the layout of the various rings around the image (...
Definition: ImageState.cs:42
string RelativeTo
Specifies the container that the position values (top,left,right,bottom,width,heght) are relative to...
Definition: Layer.cs:129
DistanceUnit Width
The width of the layer. If used with both Left and Right, the smaller result wins. I.e, with a 100px container, width=50, left=30, right=30, the resulting width will be 40. If null, Left and Right will be used to calcuate the value. If both Left and Right are not specified, the natural width of the layer&#39;s contents will be used. Percentages are relative to the container width.
Definition: Layer.cs:107
DistanceUnit Top
The offset from the top of the container. Percentages are relative to the container height...
Definition: Layer.cs:64
DistanceUnit Right
The offset relative to the right side of the container. Percentages are relative to the container wid...
Definition: Layer.cs:87

Property Documentation

ContentAlignment ImageResizer.Plugins.Watermark.Layer.Align
getset

The alignment to use when (a) all 3 horizontal or vertical values are specified, and they need to be resolved, (b) when only width/height are specified, (c) when no positioning values are specified, or (d) when the content doesn't precisely fill they layer bounds.

Definition at line 146 of file Layer.cs.

DistanceUnit ImageResizer.Plugins.Watermark.Layer.Bottom
getset

The offset relative to the bottom of the container. Percentages are relative to the container height. Defines the bottom-most boundary for the layer. If null, Top will be used to calcuate the value based on the height. If Top is not specified, defaults to 0. Positive values are inside the container, negative values outside it.

Definition at line 97 of file Layer.cs.

LayerPlacement ImageResizer.Plugins.Watermark.Layer.DrawAs
getset

The z-order at which to draw the layer. Curret options are Overlay (over everything) and Background (over the background color).

Definition at line 170 of file Layer.cs.

bool ImageResizer.Plugins.Watermark.Layer.Fill
getset

(defaults false). When true, the image or text will attempt to fill 1 of the layer's bounds, even if upscaling is required. When Width is not specified, and both left and right are not specififed, this causes the image to fill the container width (if possible). When Height is not specified, and both top and bottom are not specififed, this causes the image to fill the container height (if possible). This causes &scale=both to be used on images unless another setting is specified in imageQuery.

Definition at line 159 of file Layer.cs.

DistanceUnit ImageResizer.Plugins.Watermark.Layer.Height
getset

The height of the layer. If used with both Top and Bottom, the smaller result wins. I.e, with a 100px container, height=50, top=30, top=30, the resulting height will be 40. If null, Top and Bottom will be used to calcuate the value. If both Top and Bottom are not specified, the natural height of the layer's contents will be used. Percentages are relative to the container height.

Definition at line 118 of file Layer.cs.

DistanceUnit ImageResizer.Plugins.Watermark.Layer.Left
getset

The offset from the left of the container. Percentages are relative to the container width. Defines the leftmost boundary for the layer. If null, Right will be used to calcuate the value based on the width. If Right is not specified, defaults to 0. Positive values are inside the container, negative values outside it.

Definition at line 75 of file Layer.cs.

string ImageResizer.Plugins.Watermark.Layer.RelativeTo
getset

Specifies the container that the position values (top,left,right,bottom,width,heght) are relative to. The default is 'image' (the innermost square, which contains the original photo). Additional valid values include 'imageArea' (includes whitespace added to preserve aspect ratio), 'padding', 'border', 'margin', and 'canvas'.

Definition at line 129 of file Layer.cs.

DistanceUnit ImageResizer.Plugins.Watermark.Layer.Right
getset

The offset relative to the right side of the container. Percentages are relative to the container width. Defines the rightmost boundary for the layer. If null, Top will be used to calcuate the value based on the height. If Top is not specified, defaults to 0. Positive values are inside the container, negative values outside it.

Definition at line 87 of file Layer.cs.

DistanceUnit ImageResizer.Plugins.Watermark.Layer.Top
getset

The offset from the top of the container. Percentages are relative to the container height. Defines the upper boundary for the layer. If null, Bottom will be used to calcuate the value based on the height. If Bottom is not specified, defaults to 0. Positive values are inside the container, negative values outside it.

Definition at line 64 of file Layer.cs.

DistanceUnit ImageResizer.Plugins.Watermark.Layer.Width
getset

The width of the layer. If used with both Left and Right, the smaller result wins. I.e, with a 100px container, width=50, left=30, right=30, the resulting width will be 40. If null, Left and Right will be used to calcuate the value. If both Left and Right are not specified, the natural width of the layer's contents will be used. Percentages are relative to the container width.

Definition at line 107 of file Layer.cs.


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