Table of Contents

Class Recipe

Namespace
ToSic.Sxc.Images
Assembly
ToSic.Sxc.dll

A recipe contains instructions how to generate tags etc. which can contain multiple resized images

[InternalApi_DoNotUse_MayChangeWithoutNotice("Still Beta / WIP")]
public class Recipe : ICanDump
Inheritance
Recipe
Implements

Remarks

All the properties are read-only. If you need to override anything, copy it and set the modified values, then use the copy.

Constructors

Recipe(string, string, string, string, int, bool?, bool?, string, IDictionary<string, object>, IEnumerable<Recipe>)

Lighter constructor for json, without parameter Recipe.

Important If you call this from your code, always use named parameters, as the parameter order can change in future.

[JsonConstructor]
public Recipe(string name = null, string forTag = null, string forFactor = null, string forCss = null, int width = 0, bool? setWidth = null, bool? setHeight = null, string variants = null, IDictionary<string, object> attributes = null, IEnumerable<Recipe> recipes = null)

Parameters

name string

An optional name

forTag string

Restricts the rule to only apply to specific tags - ATM img and source

forFactor string

Restricts the rule to only apply to resizes for a specified factor

forCss string

Restricts the rule to only apply to pages which have the specified CSS Framework

width int

Initial width to use when resizing

setWidth bool?

Set the width attribute if the img width is known

setHeight bool?

Set the height attribute if the img-height is known

variants string

Special string containing variants to generate

attributes IDictionary<string, object>

List of attributes to set on the img tag

recipes IEnumerable<Recipe>

List of additional recipes which will all inherit values from this master after creation

Recipe(Recipe, string, string, string, string, int, bool?, bool?, string, IDictionary<string, object>, IEnumerable<Recipe>)

Important

If you call this from your code, always use named parameters, as the parameter order can change in future.

public Recipe(Recipe original, string name = null, string forTag = null, string forFactor = null, string forCss = null, int width = 0, bool? setWidth = null, bool? setHeight = null, string variants = null, IDictionary<string, object> attributes = null, IEnumerable<Recipe> recipes = null)

Parameters

original Recipe

An original recipe to copy if we want to get a modified recipe based on one which already existed.

name string

An optional name

forTag string

Restricts the rule to only apply to specific tags - ATM img and source

forFactor string

Restricts the rule to only apply to resizes for a specified factor

forCss string

Restricts the rule to only apply to pages which have the specified CSS Framework

width int

Initial width to use when resizing

setWidth bool?

Set the width attribute if the img width is known

setHeight bool?

Set the height attribute if the img-height is known

variants string

Special string containing variants to generate

attributes IDictionary<string, object>

List of attributes to set on the img tag

recipes IEnumerable<Recipe>

List of additional recipes which will all inherit values from this master after creation

Properties

Attributes

Attributes to add to the img tag

public IDictionary<string, object> Attributes { get; }

Property Value

IDictionary<string, object>

Remarks

System.Text.Json requires that the case-insensitive property name and type match the parameter in the constructor. We are using string/object because a value could also be { "name": true, "other-name": 5 } in the json configuration

ForCss

WIP, not implemented yet

public string ForCss { get; set; }

Property Value

string

ForFactor

Determines which factors this recipe should be applied to. Null means any factor.

public string ForFactor { get; }

Property Value

string

ForTag

TODO: DOC

  • img, source
public string ForTag { get; }

Property Value

string

Name

Just an identifier - no technical use

public string Name { get; }

Property Value

string

Recipes

wip TODO: DOC

public IEnumerable<Recipe> Recipes { get; }

Property Value

IEnumerable<Recipe>

Remarks

System.Text.Json requires that the case-insensitive property name and type match the parameter in the constructor.

SetHeight

Determines if the img tag will receive a height-attribute

public bool? SetHeight { get; }

Property Value

bool?

SetWidth

Determines if the img tag will receive a width-attribute

public bool? SetWidth { get; }

Property Value

bool?

Variants

Source-Set rules (comma separated) which will determine what will be generated.

Examples:

  • 1x,1.5x,2x - screen resolutions
  • 200w,400w,600w,800w,1000w - pixel sizes
  • 0.5*,1*,1.5*,2* - multipliers of the originally specified pixel size

Important: According to the HTML standard you can mix pixel-sizes and multipliers, but not resolutions with any of the other types.

public string Variants { get; }

Property Value

string

Width

The initial width to assume in this resize, from which other sizes would be calculated.

If set to 0, it will be ignored.

public int Width { get; }

Property Value

int

Methods

Dump()

Create a string dump of the current objects state/contents.

public string Dump()

Returns

string