Table of Contents

Class ImageTagHelper

Namespace
SixLabors.ImageSharp.Web.TagHelpers
Assembly
SixLabors.ImageSharp.Web.dll

A TagHelper implementation targeting <img> element that allows the automatic generation image processing commands.

[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
Inheritance
ImageTagHelper
Implements
Inherited Members

Constructors

ImageTagHelper(IOptions<ImageSharpMiddlewareOptions>, RequestAuthorizationUtilities, IUrlHelperFactory, HtmlEncoder)

Initializes a new instance of the ImageTagHelper class.

public ImageTagHelper(IOptions<ImageSharpMiddlewareOptions> options, RequestAuthorizationUtilities authorizationUtilities, IUrlHelperFactory urlHelperFactory, HtmlEncoder htmlEncoder)

Parameters

options IOptions<ImageSharpMiddlewareOptions>

The middleware configuration options.

authorizationUtilities RequestAuthorizationUtilities

Contains helpers that allow authorization of image requests.

urlHelperFactory IUrlHelperFactory

The URL helper factory.

htmlEncoder HtmlEncoder

The HTML encorder.

Properties

AnchorPosition

Gets or sets the anchor position.

[HtmlAttributeName("imagesharp-ranchor")]
public AnchorPositionMode? AnchorPosition { get; set; }

Property Value

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.

[HtmlAttributeName("imagesharp-autoorient")]
public bool? AutoOrient { get; set; }

Property Value

bool?

BackgroundColor

Gets or sets the background color of the image.

[HtmlAttributeName("imagesharp-bgcolor")]
public Color? BackgroundColor { get; set; }

Property Value

Color?

Center

Gets or sets the center coordinates.

[HtmlAttributeName("imagesharp-rxy")]
public PointF? Center { get; set; }

Property Value

PointF?

Compand

Gets or sets a value indicating whether to compress or expand individual pixel colors values on processing.

[HtmlAttributeName("imagesharp-compand")]
public bool? Compand { get; set; }

Property Value

bool?

Format

Gets or sets the image format to convert to.

[HtmlAttributeName("imagesharp-format")]
public FormatCommand? Format { get; set; }

Property Value

FormatCommand?

Height

Gets or sets the height in pixel units.

[HtmlAttributeName("imagesharp-height")]
public int? Height { get; set; }

Property Value

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.

public override int Order { get; }

Property Value

int

Remarks

Default order is 0.

Orient

Gets or sets a value indicating whether to factor embedded EXIF orientation property values during processing.

[HtmlAttributeName("imagesharp-orient")]
public bool? Orient { get; set; }

Property Value

bool?

Remarks

Defaults to true.

PadColor

Gets or sets the color to use as a background when padding an image.

[HtmlAttributeName("imagesharp-rcolor")]
public Color? PadColor { get; set; }

Property Value

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).

[HtmlAttributeName("imagesharp-quality")]
public int? Quality { get; set; }

Property Value

int?

ResizeMode

Gets or sets the resize mode.

[HtmlAttributeName("imagesharp-rmode")]
public ResizeMode? ResizeMode { get; set; }

Property Value

ResizeMode?

Sampler

Gets or sets the sampling algorithm to use when resizing images.

[HtmlAttributeName("imagesharp-rsampler")]
public ResamplerCommand? Sampler { get; set; }

Property Value

ResamplerCommand?

Src

Gets or sets the src.

[HtmlAttributeName("src")]
public string? Src { get; set; }

Property Value

string

Remarks

Passed through to the generated HTML in all cases.

Width

Gets or sets the width in pixel units.

[HtmlAttributeName("imagesharp-width")]
public int? Width { get; set; }

Property Value

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.

protected virtual void AddProcessingCommands(TagHelperContext context, TagHelperOutput output, CommandCollection commands, CultureInfo commandCulture)

Parameters

context TagHelperContext

Contains information associated with the current HTML tag.

output TagHelperOutput

A stateful HTML element used to generate an HTML tag.

commands CommandCollection

The command collection.

commandCulture CultureInfo

The culture to use when generating and processing commands.

Process(TagHelperContext, TagHelperOutput)

Synchronously executes the TagHelper with the given context and output.

public override void Process(TagHelperContext context, TagHelperOutput output)

Parameters

context TagHelperContext

Contains information associated with the current HTML tag.

output TagHelperOutput

A stateful HTML element used to generate an HTML tag.