This method returns the best matching version of the source image based on the passed-in definition. Usually, applications do not need to use this method because Scrivito.ImageTag
and Scrivito.BackgroundImageTag
automatically deliver optimized images. Only applicable to a Binary
if it represents an image.
This method does not change the binary. Instead, it instructs Scrivito to select an image from a pool of resized versions. The selected version is the one that best matches the provided definition.
The optimizeFor
method returns a Binary
instance in which the definition passed to the method is stored. The image version that fits best is only determined as this instance’s data is accessed, for example via binary.url
.
The image version that fits best is selected at best effort, meaning:
- Scrivito examines the requested dimensions and chooses a down-scaled image that provides a sufficiently high resolution for that size.
- The returned image may be larger or smaller than requested but is approximately of the requested size, so it may be twice as large in one dimension but not 10 times as large.
- A requested
fit
withcrop
causes an image version to be returned which is most suitable for applying the cropping, e.g. using CSS.