- Documentation
Torch Object Storage
User Guide
Data processing
Image processing
Resize
Resize
The resize feature allows you to adjust the dimensions of images stored in TOS. This topic introduces the parameters and provides examples of the resize feature.
Supported parameters
Resizing to a specific width and height
tip
- Required: In order to use the resize feature, you must specify at least one of the required parameters. Failure to do so will result in a MissingArgument error.
- Long side: The side of the image with a larger ratio of original to target dimensions.
- Short side: The side of the image with a smaller ratio of original to target dimensions.
Resizing by a percentage
Determining parameter priority and the bounding box
- When both w and h are specified, the bounding box is constructed using the provided w and h values directly.
- When only one of w or h is specified:
- In lfit, mfit, and fixed modes, the unspecified dimension is calculated based on the aspect ratio of the original image to form the bounding box.
- For the fill and pad modes, a square bounding box is constructed using the specified dimension.
- When neither w nor h is specified:
- If both l and s are specified, the bounding box is constructed with the long side set to l and the short side set to s.
- If only one of l or s is specified:
- In lfit, mfit, and fixed modes, the unspecified dimension is calculated based on the aspect ratio of the original image to form the bounding box.
- For the fill and pad modes, a square bounding box is constructed using the specified dimension.
- If neither l nor s is specified, proportional resizing is performed using the p parameter.
Resizing an image based on the given parameters
In this section, we will show you how images are resized based on the parameters you provide. The original image size is 400 by 200 pixels.
- A bounding box of 100x100 is created when both w and h are set to 100, based on the parameter priorities. The resized images produced under various modes are as follows:
lfit mode
mfit mode
fixed mode
fill mode
pad mode
The image is proportionally scaled down. The result is an image that fits entirely within the 100x50 bounding box.
The image is proportionally scaled down. The result is the smallest image that can fully cover the 200x100 bounding box.
The image is resized to the specified width and height of 100x100 pixels, regardless of the original aspect ratio.
First, the image is resized using mfit logic to create a 200x100 pixel image. Then, the resized image is centered within the bounding box. Any portions extending beyond the box are cropped, resulting in a final image size of 100x100 pixels.
First, the image is resized using lfit logic to create a 100x50 pixel image. Then, the resized image is centered within the bounding box. Any remaining blank areas are filled with the specified color to produce the final 100x100 pixel image.
- Based on the parameter priorities and the aspect ratio of the original image (2:1), if w is set to 200, h is calculated as 100. This results in a bounding box of 200x100, and the resizing operation proceeds as described above.
- Setting l to 200 and s to 100 results in a bounding box with a long side of 200 and a short side of 100. Since the width of the original image corresponds to the long side and the height corresponds to the short side, the resulting bounding box is sized 200x100. The resizing operation then proceeds as described above.
- Setting l to 200, with the width of the original image as the long side and an aspect ratio of 2:1, results in a bounding box of 200x100. The resizing operation then proceeds as described above.
Examples
tip
This guide uses the same static image for all examples.
- Set the width to 100 for proportional resizing.
-
- Set the height to 100 for proportional resizing.
-
- Set the long side to 100 for proportional resizing.
-
- Set the short side to 100 for proportional resizing.
-
- Set the height and width to 200 and the mode to lfit.
-
- Set the height and width to 200 and the mode to mfit.
-
- Set the height and width to 200 and the mode to fixed.
-
- Set the height and width to 200 and the mode to fill.
-
- Set the height and width to 200, the mode to pad, and the color to FF0000 (red).
-
- Resize the image proportionally to 30%.
-
Last updated: 2026.02.03 17:51:49