Interface IImageService
Service on Kit.Image to help create responsive img and picture tags the best possible way.
This service helps you generate advanced HTML for responsive / resized images.
Tip
We suggest you read the Image Guide for maximum power!
[PublicApi]
public interface IImageService : ICanDebug
- Inherited Members
Remarks
History: Released 2sxc 13.10
Methods
Img(object?, object?, NoParamOrder, Func<ITweakMedia, ITweakMedia>?, object?, object?, string?, string?, string?, object?, object?, object?)
Get a Responsive Image object which you can then either just show, or use to construct a more customized output as you need it.
The resulting object can just be added to the html, like @img or you can work with sub-properties as specified in the IResponsiveImage
IResponsiveImage Img(object? link = null, object? settings = null, NoParamOrder noParamOrder = default, Func<ITweakMedia, ITweakMedia>? tweak = null, object? factor = null, object? width = null, string? imgAlt = null, string? imgAltFallback = null, string? imgClass = null, object? imgAttributes = null, object? toolbar = null, object? recipe = null)
Parameters
linkobjectWhat should be in this, can be:
- a string url, in which case it would be used if
urlis not specified - a IField in which case it would be used if
fieldis not specified
- a string url, in which case it would be used if
settingsobject- The name of a settings configuration, like "Content", "Screen", "Square", etc.
- A standardized Image-Settings object like Settings.Images.Content - see https://go.2sxc.org/settings
- Or a dynamic object containing settings properties (this can also be a merged custom + standard settings)
- A IResizeSettings object containing all settings created using ResizeSettings
noParamOrderNoParamOrdertweakFunc<ITweakMedia, ITweakMedia>Tweak API to configure everything (new v18.03). This is recommended above using parameter names and all newer parameters will only be available on this. Note that tweak will be executed after applying other parameters.
factorobjectAn optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
widthobjectAn optional, fixed width of the image
imgAltstringOptional
altattribute on the createdimgtag for SEO etc. If supplied, it takes precedence to the alt-description in the image metadata which the editor added themselves. If you want to provide a fallback value (in case the metadata has no alt), useimgAltFallback.imgAltFallbackstringOptional
altattribute which is only used if theimgAltor the alt-text in the metadata are empty. new in v15imgClassstringOptional
classattribute on the createdimgtagimgAttributesobjectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }or Dictionary (new 16.07)toolbarobjectProvide a custom toolbar or
falseto not show a toolbarrecipeobjectOptional recipe = instructions how to create the various variants of this link. Can be any one of these:
- string containing variants
- Rule object
TODO: DOCS not quite ready
Returns
- IResponsiveImage
A ResponsiveImage object which can be rendered directly. See Responsive Images API in .net
Remarks
- Added in 2sxc 13.03
toolbaradded in v16.04tweakadded in 18.03
Picture(object?, object?, NoParamOrder, Func<ITweakMedia, ITweakMedia>?, object?, object?, string?, string?, string?, object?, string?, object?, object?, object?)
Get a Responsive Picture object which you can then either just show, or use to construct a more customized output as you need it.
The resulting object can just be added to the html, like @pic or you can work with sub-properties as specified in the IResponsivePicture.
Important: This call only allows you to set the most common parameters factor and width.
For other parameters like height, aspectRatio, quality etc. create Settings Settings(object?, NoParamOrder, Func<ITweakResize, ITweakResize>?, object?, object?, object?, object?, string?, string?, string?, object?, string?, object?) and pass them in.
IResponsivePicture Picture(object? link = null, object? settings = null, NoParamOrder noParamOrder = default, Func<ITweakMedia, ITweakMedia>? tweak = null, object? factor = null, object? width = null, string? imgAlt = null, string? imgAltFallback = null, string? imgClass = null, object? imgAttributes = null, string? pictureClass = null, object? pictureAttributes = null, object? toolbar = null, object? recipe = null)
Parameters
linkobjectWhat should be in this, can be:
settingsobject- The name of a settings configuration, like "Content", "Screen", "Square", etc.
- A standardized Image-Settings object like Settings.Images.Content - see https://go.2sxc.org/settings
- Or a dynamic object containing settings properties (this can also be a merged custom + standard settings)
- A IResizeSettings object containing all settings created using ResizeSettings
noParamOrderNoParamOrdertweakFunc<ITweakMedia, ITweakMedia>Tweak API to configure everything (new v18.03). This is recommended above using parameter names and all newer parameters will only be available on this. Note that tweak will be executed after applying other parameters.
factorobjectAn optional multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
widthobjectAn optional, fixed width of the image
imgAltstringOptional
altattribute on the createdimgtag for SEO etc. If supplied, it takes precedence to the alt-description in the image metadata which the editor added themselves. If you want to provide a fallback value (in case the metadata has no alt), useimgAltFallbackimgAltFallbackstringOptional
altattribute which is only used if theimgAltor the alt-text in the metadata are empty. new in v15imgClassstringOptional
classattribute on the createdimgtagimgAttributesobjectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }or Dictionary (new 16.07)pictureClassstringOptional
classattribute on the createdpicturetagpictureAttributesobjectOptional additional attributes - as anonymous object like
new { style = "padding: 10px" }or Dictionary (new 16.07)toolbarobjectProvide a custom toolbar or
falseto not show a toolbarrecipeobjectOptional recipe = instructions how to create the various variants of this link. Can be any one of these:
- string containing variants
- Rule object
TODO: DOCS not quite ready
Returns
- IResponsivePicture
A ResponsivePicture object which can be rendered directly. See Responsive Images API in .net
Remarks
- Added in v13.03
- Extended in v16.03 to also support IFile
toolbaradded in v16.04imgAttributes,picClassandpicAttributesadded in 16.07tweakadded in 18.03
Recipe(string)
Recipe Recipe(string variants)
Parameters
variantsstring
Returns
Recipe(Recipe, NoParamOrder, string?, int, string?, IDictionary<string, object?>?, IEnumerable<Recipe>?, bool?, bool?, string?, string?, string?)
Recipe Recipe(Recipe recipe, NoParamOrder noParamOrder = default, string? name = null, int width = 0, string? variants = null, IDictionary<string, object?>? attributes = null, IEnumerable<Recipe>? recipes = null, bool? setWidth = null, bool? setHeight = null, string? forTag = null, string? forFactor = null, string? forCss = null)
Parameters
recipeRecipenoParamOrderNoParamOrdernamestringwidthintvariantsstringattributesIDictionary<string, object>recipesIEnumerable<Recipe>setWidthbool?setHeightbool?forTagstringforFactorstringforCssstring
Returns
Settings(object?, NoParamOrder, Func<ITweakResize, ITweakResize>?, object?, object?, object?, object?, string?, string?, string?, object?, string?, object?)
Construct custom Resize-Settings as needed, either based on existing settings or starting from scratch
IResizeSettings Settings(object? settings = null, NoParamOrder noParamOrder = default, Func<ITweakResize, ITweakResize>? tweak = null, object? factor = null, object? width = null, object? height = null, object? quality = null, string? resizeMode = null, string? scaleMode = null, string? format = null, object? aspectRatio = null, string? parameters = null, object? recipe = null)
Parameters
settingsobject- A standardized Image-Settings object like
Settings.Images.Contentused as a template - see https://go.2sxc.org/settings - The
stringname of a template settings , like "Content" or "Screen" - a
booltrue/false - if true, the normal "Content" configuration is used as a template, if false, no initial configuration is used - Or a dynamic object containing settings properties (this can also be a merged custom + standard settings)
- Or a specially prepared IResizeSettings object containing all settings.
- A standardized Image-Settings object like
noParamOrderNoParamOrdertweakFunc<ITweakResize, ITweakResize>Tweak API to configure everything (new v18.03). This is recommended above using parameter names and all newer parameters will only be available on this. Note that tweak will be executed after applying other parameters.
factorobjectA multiplier, usually used to create urls which resize to a part of the default content-size. Like 0.5.
widthobjectOptional width parameter. Cannot be used if
factoris set. Usually takes the default from thesettings.heightobjectOptional height parameter. Can only be 0 if
factoris set, no not specify a height. Usually takes the default from thesettings.qualityobjectOptional quality parameter. Usually takes the default from the
settings.resizeModestringOptional resize-mode, like
cropormax. Usually takes the default from thesettings.scaleModestringOptional scale-mode to allow up-scaling images like
uporboth. Usually takes the default from thesettings.formatstringOptional file format like
jpgorpngaspectRatioobjectAspect Ratio width/height, only relevant if a
factoris supplied. Usually takes default from thesettingsor is ignored.parametersstring- the parameters either as
id=47&name=daniel(Dnn also supports/id/47/name/daniel) - it can also be an IParameters
- the parameters either as
recipeobjectWIP - not ready yet
Returns
- IResizeSettings
A settings object which has all the parameters as configured
Remarks
- Added in v13.03
- Tweak added in v18.03