Hey @gshenar,
Firstly, to answer your initial question:
The scale property takes the width and height of the asset and scales it based on the ratio you set in your JSON. It works slightly differently depending on what fit property you use.
The following examples use an image with dimensions of 400px by 102px and an output of 1280px by 720px. By default a clip always uses the crop property.
Scaling with fit property set to crop (default)
When you don’t set the fit property and set no scale your image will scale to fit the viewport.
No scale
As the example video is wider than it is tall this means it gets scaled automatically to fill the height of the viewport. In this case the implied scale equals 720 / 102 = 7.0589. This means its width will be 400px * 7.0589 = 2823.6px, and the height will be 720px.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
“Scale”: 0.5
When you set the scale property on a clip with the default crop property the clip will scale based on the size of your output resolution. In the particular case the height of the clip will be 1280px * 0.5 = 640px.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"scale": 0.5
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
Scaling with fit property set to cover
When you set the fit property to cover you stretch the asset to fill the viewport without maintaining the aspect ratio.
No scale
The clip gets scaled to fill the viewport completely. In case of its width it gets scaled by 1280px / 400px = 3.2 and its height gets scaled by 720px / 102px = 7.0589.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"fit": "cover"
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
“Scale”: 0.5
When you scale a clip with the fit property set to cover and set the scale property to 0.5 your image gets stretched to a width of 1280px * 0.5 = 640x and a height of 720px * 0.5 = 360px.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"fit": "cover",
"scale": 0.5
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
Scaling with fit property set to contain
When the fit property is set to contain the entire asset is scaled to fit within the viewport while maintaining the original aspect ratio.
No scale
In the case of this example, where the image is wider than it is tall, it will have a width of 1280px as the width of the viewport is 1280px. This effectively scales the clip by 1280px / 400px = 3.2
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"fit": "contain"
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
“Scale”: 0.5
When you scale a clip with the fit property set to contain and set the scale property to 0.5 your image gets scaled to a width of 1280px * 0.5 = 640x and a height of 102px * 3.2 * 0.5 = 163.2px.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"fit": "contain",
"scale": 0.5
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
Scaling with fit property set to none
When the fit property is set to contain the asset preserves the original asset dimensions and does not apply any scaling.
No scale
When no scaling is applied to the clip the dimensions will stay the same as the asset used. In this case setting the clip dimensions at 400px by 102px.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"fit": "none"
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}
“Scale”: 0.5
When you scale a clip with the fit property set to none and set the scale property to 0.5 your image gets scaled by the dimensions of the asset used. In this case the image will be 400px * 0.5 = 200px wide and 102px * 0.5 = 51px high.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/branding/logo-reverse.png"
},
"start": 0,
"length": 1,
"fit": "none",
"scale": 0.5
}
]
}
]
},
"output": {
"format": "png",
"resolution": "hd"
}
}