Optimizing Image Load
Last updated
Last updated
Whisk is utilizing CDN when it comes to serving images whether they are Whisk-internal or coming from third-party sources. That provides certain benefits:
By using distributed across world network, we make sure images are served from locations which are close to end-user
Because of images served from the single domain, a browser doesn't need to perform DNS-resolution for many different domains
Images are served over HTTP/2 protocol, which is super-optimal for loading multiple images at once (e.g. when displaying Recipe Feed)
All images are served securely through HTTPS (HTTP/2-ready), that provides guarantees that the browser will not provide any warnings about insecure content
In addition to fast baseline speed, a client can choose which image size to load depending on its needs. For example, it is unnecessary to load a big recipe image if you only need to request a thumbnail.
By knowing image parameters in advance, a client application can prepare an optimal layout for displaying a content image.
It is possible to implement graceful image loading by first requesting a lower-quality image and showing it as soon as possible to the end-user. Then when a higher-res image is loaded, the previous image can be replaced.
To see how graceful image loading works in Whisk, it is best to see a demo:
Download temporary image: We show an image with the following transformation first:
where e_blur
is a blur effect (range: 1 to 2000, Default: 500), q_50
is image quality (range: 1 to 100), f_auto
(optional) is the file extension of the requested delivery format for the resource.
Download full image: At the same time, we’re downloading full image. Once it has been downloaded we display it.
Assuming that base image (960x1280) URL has a form of:
You can request alternative size (300x300) by modifying url to:
You can extract a region of the given width and height out of the original image. The original proportions are retained and so is the size of the graphics. You can specify the gravity parameter to select which part of the image to extract, or use fixed coordinates cropping.
For example, the jpg image cropped to a width of 300 pixels, a height of 300 pixels, with west gravity:
You can specify a region of the original image to crop by giving the x and y coordinates of the top left corner of the region together with the width and height of the region. You can also use percentage-based numbers instead of the exact coordinates for x, y, w, and h (e.g., 0.5 for 50%). Use this method when you know beforehand what the correct absolute cropping coordinates are, as in when your users manually select the region to crop out of the original image.
To manipulate the picture so that only little white cup is visible, the image is cropped to a 300x200 region starting at the coordinate x = 480 and y = 250:
To apply a strong blurring filter (300) to the sample image:
Different devices support different DPR values, which is defined as the ratio between physical pixels and logical pixels. This means that a device with support for a higher DPR uses more physical pixels for displaying an image, resulting in a clearer, sharper image.
Use the dpr
parameter to set the DPR value of the delivered image. The parameter accepts a numeric value specifying the DPR multiplier.
The tint: effect enables you to blend your images with one or more colors and specify the blend strength. By default, e_tint applies a red color at 60% blend strength.
Specify the colors and blend strength amount in the format:
amount is a value from 0-100, where 0 keeps the original color and 100 blends the specified colors completely.
The color can be specified as an RGB hex triplet (e.g., rgb: 3e2222
), a 3-digit RGB hex (e.g., rgb: 777
) or a named color (e.g., green
).
For example:
ImageContainer is Whisk's common wrapper around the original image
Example:
ResponsiveImage contains hosted secure URL and provides information about original image dimensions
ATTRIBUTE
TYPE
DESCRIPTION
url*
string
original image url, depricated. Please use field original instead
original
OriginalImage
original image information, e.g. image url
responsive*
ResponsiveImage
ATTRIBUTE
TYPE
DESCRIPTION
url*
string
Hosted URL of an image
width*
integer
Image width
height*
integer
Image height