Hi mr_amdev,
At this point we do not allow for freehand changing of width and height of image assets, which appears what you are looking to achieve. This essentially squashes the image and removes the original aspect ratio. I have added it to the feature requests for a future release.
Cropping
What you can do is crop the image. While this maintains the aspect ratio you can fix the width based on what you need. As an example for an image of 1000px in width you can cut the left and right side of the image using the crop
property to have cut away 200px on the left and 200px on the right:
Before cropping
After cropping
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "image",
"src": "https://shotstack-assets.s3.amazonaws.com/images/waterfall.jpeg",
"crop": {
"left": 0.2,
"right": 0.2
}
},
"start": 0,
"length": 1
}
]
}
]
},
"output": {
"format": "jpg",
"size": {
"width": 800,
"height": 667
}
}
}
The crop property uses a ratio relative to the original width and height of the image asset. If you want to use pixels you’ll need a function that will convert those pixels to a ratio similar to the following:
const convertPixelsToDecimals = (target, original) => {
let percentage = 1 - ((original - target) / original);
return Math.round(percentage * 1000) / 1000;
}
Media Inspector
You would be able to get the original asset dimensions using the media inspector API by calling your image or video asset using the following url:
https://api.shotstack.io/edit/v1/probe/https%3A%2F%2Fshotstack-assets.s3.amazonaws.com%2Fimages%2Fwaterfall.jpeg
Just make sure to encode the URL you want to inspect.
This will give you something like the following (truncated a bit for readability):
{
"success": true,
"message": "ok",
"response": {
"metadata": {
"streams": [
{
"codec_name": "mjpeg",
"codec_long_name": "Motion JPEG",
"profile": "Progressive",
"width": 1000,
"height": 667,
"coded_width": 1000,
"coded_height": 667,
"display_aspect_ratio": "1000:667",
"pix_fmt": "yuvj420p",
"bits_per_raw_sample": "8",
}
],
"format": {
"filename": "https://shotstack-assets.s3.amazonaws.com/images/waterfall.jpeg",
"format_name": "image2",
"duration": "0.040000",
"size": "306648",
"bit_rate": "61329600"
}
}
}
}