Add support for image optimization #63
Labels
groomed
The issue has been groomed and should be in a good shape.
hacktoberfest
https://hacktoberfest.digitalocean.com/
help wanted
up-for-grabs
Kentico Kontent now supports image optimization. It gives developers the option of transforming images using URL parameters. The goal of this task is to implement a helper class that will make generation of image URLs easy for the developers.
The reference code can be observed in the .NET SDK.
The full specification follows:
Example
Scale
image.jpg?mode=scale&width=300
image.jpg?mode=scale&height=150
image.jpg?mode=fit&height=150&width=300
DPR
image.jpg?mode=scale&width=300&dpr=2.0
Specification
If a developer provides a parameter with invalid value or omits a parameter that is required for desired optimization, the Asset API will either ignore this parameter, or return the original asset without any optimizations.
Also, to keep our sanity, we will transform each image optimization parameter independently from others. Yes, this approach might sometimes produce surprising results. However, both Fastly and imgix are designed to handle a set of parameters that do not make sense and we are not making the situation worse.
Regarding requests to the Asset API, the idea is to go through all parameters, transform the supported ones and get rid of everything else.
To get a grasp of the image optimization You can experiment with two identical images:
rect=x,y,w,h (incompatible with crop)
If the
rect
parameter is malformed, just ignore it.fit=crop&crop=focalpoint&fp-x=x&fp-y=y&fp-z=z (incompatible with rect)
Both offset-x and offset-y must be clamped into range from 0 to 100.
imgix supports crop by both rectangle and focal point. Unfortunately, it is not so easy to calculate Fastly parameters. Therefore, let's declare the
rect
parameter more important. So, if both crop by rectangle and focal point are specified, choose the first.fm=x
fm=webp&lossless=x
q=x
auto=x
Local variables and related functions will be required to transform parameters.
The text was updated successfully, but these errors were encountered: