Class ImageTagHelper
A TagHelper implementation targeting <img> element that allows the automatic generation image processing commands.
Inherited Members
Namespace: SixLabors.ImageSharp.Web.TagHelpers
Assembly: SixLabors.ImageSharp.Web.dll
Syntax
[HtmlTargetElement("img", Attributes = "src,imagesharp-width", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-height", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-ranchor", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-rmode", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-rxy", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-rcolor", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-compand", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-orient", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-autoorient", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-format", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-bgcolor", TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("img", Attributes = "src,imagesharp-quality", TagStructure = TagStructure.WithoutEndTag)]
public class ImageTagHelper : UrlResolutionTagHelper, ITagHelper, ITagHelperComponent
Constructors
ImageTagHelper(IOptions<ImageSharpMiddlewareOptions>, RequestAuthorizationUtilities, IUrlHelperFactory, HtmlEncoder)
Initializes a new instance of the ImageTagHelper class.
Declaration
public ImageTagHelper(IOptions<ImageSharpMiddlewareOptions> options, RequestAuthorizationUtilities authorizationUtilities, IUrlHelperFactory urlHelperFactory, HtmlEncoder htmlEncoder)
Parameters
| Type | Name | Description |
|---|---|---|
| IOptions<ImageSharpMiddlewareOptions> | options | The middleware configuration options. |
| RequestAuthorizationUtilities | authorizationUtilities | Contains helpers that allow authorization of image requests. |
| IUrlHelperFactory | urlHelperFactory | The URL helper factory. |
| HtmlEncoder | htmlEncoder | The HTML encorder. |
Properties
AnchorPosition
Gets or sets the anchor position.
Declaration
[HtmlAttributeName("imagesharp-ranchor")]
public AnchorPositionMode? AnchorPosition { get; set; }
Property Value
| Type | Description |
|---|---|
| AnchorPositionMode? |
AutoOrient
Gets or sets a value indicating whether to automatically rotate/flip the input image based on embedded EXIF orientation property values before processing.
Declaration
[HtmlAttributeName("imagesharp-autoorient")]
public bool? AutoOrient { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
BackgroundColor
Gets or sets the background color of the image.
Declaration
[HtmlAttributeName("imagesharp-bgcolor")]
public Color? BackgroundColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color? |
Center
Gets or sets the center coordinates.
Declaration
[HtmlAttributeName("imagesharp-rxy")]
public PointF? Center { get; set; }
Property Value
| Type | Description |
|---|---|
| PointF? |
Compand
Gets or sets a value indicating whether to compress or expand individual pixel colors values on processing.
Declaration
[HtmlAttributeName("imagesharp-compand")]
public bool? Compand { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Format
Gets or sets the image format to convert to.
Declaration
[HtmlAttributeName("imagesharp-format")]
public FormatCommand? Format { get; set; }
Property Value
| Type | Description |
|---|---|
| FormatCommand? |
Height
Gets or sets the height in pixel units.
Declaration
[HtmlAttributeName("imagesharp-height")]
public int? Height { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
Remarks
Passed through to the generated HTML in all cases.
Order
When a set of ITagHelpers are executed, their Init(TagHelperContext)'s are first invoked in the specified Order; then their ProcessAsync(TagHelperContext, TagHelperOutput)'s are invoked in the specified Order. Lower values are executed first.
Declaration
public override int Order { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Remarks
Default order is 0.
Orient
Gets or sets a value indicating whether to factor embedded EXIF orientation property values during processing.
Declaration
[HtmlAttributeName("imagesharp-orient")]
public bool? Orient { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Remarks
Defaults to true.
PadColor
Gets or sets the color to use as a background when padding an image.
Declaration
[HtmlAttributeName("imagesharp-rcolor")]
public Color? PadColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color? |
Quality
Gets or sets the quality, that will be used to encode the image. Quality index must be between 0 and 100 (compression from max to min).
Declaration
[HtmlAttributeName("imagesharp-quality")]
public int? Quality { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
ResizeMode
Gets or sets the resize mode.
Declaration
[HtmlAttributeName("imagesharp-rmode")]
public ResizeMode? ResizeMode { get; set; }
Property Value
| Type | Description |
|---|---|
| ResizeMode? |
Sampler
Gets or sets the sampling algorithm to use when resizing images.
Declaration
[HtmlAttributeName("imagesharp-rsampler")]
public ResamplerCommand? Sampler { get; set; }
Property Value
| Type | Description |
|---|---|
| ResamplerCommand? |
Src
Gets or sets the src.
Declaration
[HtmlAttributeName("src")]
public string? Src { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Passed through to the generated HTML in all cases.
Width
Gets or sets the width in pixel units.
Declaration
[HtmlAttributeName("imagesharp-width")]
public int? Width { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
Remarks
Passed through to the generated HTML in all cases.
Methods
AddProcessingCommands(TagHelperContext, TagHelperOutput, CommandCollection, CultureInfo)
Allows the addition of processing commands by inheriting classes.
Declaration
protected virtual void AddProcessingCommands(TagHelperContext context, TagHelperOutput output, CommandCollection commands, CultureInfo commandCulture)
Parameters
| Type | Name | Description |
|---|---|---|
| TagHelperContext | context | Contains information associated with the current HTML tag. |
| TagHelperOutput | output | A stateful HTML element used to generate an HTML tag. |
| CommandCollection | commands | The command collection. |
| CultureInfo | commandCulture | The culture to use when generating and processing commands. |
Process(TagHelperContext, TagHelperOutput)
Synchronously executes the TagHelper with the given context and
output.
Declaration
public override void Process(TagHelperContext context, TagHelperOutput output)
Parameters
| Type | Name | Description |
|---|---|---|
| TagHelperContext | context | Contains information associated with the current HTML tag. |
| TagHelperOutput | output | A stateful HTML element used to generate an HTML tag. |