Zoom / crop / rotate / format conversion

Last updated:2020-08-21 18:14:28

Image Processing


Scaling, cropping, auto-rotating, format conversion, progressive display

Interface

imageScale

Description

This function provides the image scaling, cropping, rotating, format conversion and progressive display.

Multiple scaling modes are supported:

1.Specify the width and height

  • Set the thumbnail width only, and scale according to the width;
  • Set the thumbnail height only, and scale according to the height;
  • Set the width and height, and scale proportionally according to long side without setting to scale the image by short side;
  • Set the width and height, and scale proportionally according to short side when it is set to scale the image by short side;
  • Set the width and height of the image and the background, and fill the thumbnail (For BMP image files, it is recommended to use the pipeline to fill the thumbnail).

Notes
If you want to zoom in the image, please use the parameter so and set its value to 1. It is not necessary to specify so when you zoom in the image proportionally.

2.Proportional scaling

Percentage. If it is smaller than 100, it means scaling down the image; and if it is bigger than 100, it means scaling up the image. The parameter value range is 1-1000.

There are the following restrictions when you zoom in the image:

  • The pixel value * multiple of long side of the image can be up to 5000;
  • When the image size is less than or equal to 1 MB, it can be enlarged by up to 10 times, when the image size is greater than 1 MB and less than 2 MB, it can be enlarged by up to 5 times, and when the image size is greater than 2 MB, it can be enlarged by up to 3 times.

There are three ways to use the cropping function:

  • Centered cropping: after the image is scaled, perform the centered cropping to the part outside the predefined range. The cropping will occur only when the thumbnail width and height are set;
  • When the fixed width and height have been set, the cropping will be centered cropped as per the fixed width and height.
  • Cropping at any position: set the starting horizontal coordinate and starting vertical coordinate, and set the cropping width and height.

Rotating:

  • Rotate the image according to the rotation angle contained in Exif information.

Format conversion:

  • The image can be output in the specified format. The output format includes JPG, JPEG, PNG, GIF, WBMP, BMP and WEBP.

Please note that the order of four operations is rotating, scaling, cropping and format conversion, regardless of the order of the specified parameters.

Progressive display:

There are two ways to present the image in jpg or jpeg format:

  • Top-down scanning
  • Fuzzy first and then gradually clear (when the network environment is poor)

The default is that the first option is saved. If you want to specify a presentation that is fuzzy first and then clear, use the progressive display parameters.

Permission

You need the GetObject permission for this operation. If the object you request does not exist, you may have the following two errors returned:

  • If you have the ListBucket permission on the bucket of this object, the status code 404 error will be returned;
  • If you don’t have the ListBucket permission on the bucket of this object, the status code 403 error will be returned.

Request

Syntax
https://BucketName.${domain name of the region where the bucket is located}/[email protected]@
	tag=imgScale   
	&m=<mode>   
	&w=<width>   
	&h=<height>   
	&q=<quality>   
	&F=<format>   
	&r=<auto-orient>   
	&c=<cut>   
	&f=<fixed>     
	&s=<strip>
	&cox=<x-coordinate>
	&coy=<y-coordinate>
	&rotate=<degree>
	&et=<extent>
	&etw=<extent width>
	&eth=<extent height>
	&etc=<extent colour>    
HTTP/1.1
Host: BucketName.${domain name of the region where the bucket is located}
Request parameters:
Parameter Parameter meaning Mandatory Default Value range Explanation
tag Operation flag Yes
m Scaling mode No 0 0Long side will be scaled first according to the scaling ratio of long side, without the cropping
1Short side will be scaled first according to the scaling ratio of short side, without the cropping
2Limit the width of the thumbnail to at least <width>, and the height to at least <height> to perform proportional scaling
w Scaling width/cropping width One of w/h must be present 1-4096 Specify the width of the target thumbnail or cropped image in pixels (px). When it is used alone, it means proportional scaling according to the width
h Scaling height/cropping height One of w/h must be present 1-4096 Specify the height of the target thumbnail or cropped image in pixels (px). When it is used alone, it means proportional scaling according to the height
p Proportional scaling of the image No 1-1000 Multiple percentage. If it is smaller than 100, it means to scale down; and if it is bigger than 100, it means to scale up.
When the image is scaled up, the p value range is:
when the image size is less than or equal to 1 MB, it can be enlarged by up to 10 times; when the image size is greater than 1 MB and less than 2 MB, it can be enlarged by up to 5 times; and when the image size is greater than 2 MB, it can be enlarged by up to 3 times.
The pixel value * multiple of long side of the image can be up to 5000
so Image scale-up No 0 When the value is 1, the image scale-up is enabled It is specified as the scale-up mode
q Image quality No 75 0-100 Determine the relative quality of the jpg image and compress the source image. 0 indicates high compression ratio and low quality, and 100 indicates low compression ratio and high quality
F Target thumbnail output format No The image will be output in original image format. The output format includes JPG, JPEG, PNG, GIF, WBMP, BMP and WEBP
r Rotation mode No 0 0The image is processed as per the source image by default
1Auto-rotate the image as per EXIF information of the source image
2You define the rotation angle. The rotation angle is specified by the <rotate> parameter
c Cropping No 0 0No cropping
1Crop the image out of the range after it is scaled. This usually happens in proportional scaling according to short side first. The scaling will be to crop the top and bottom/left and right side of the image around the center line of the image to get the corresponding size
f Fixed width and height No 0 0Not fixed width and height
1Crop the area with specified width and height around the center line of the image. This parameter is used along with the parameter cut. When f is used, the width and height of the image will be fixed, and the non-scaling cropping will be performed
s Support for the metadata removal No 1 0 Not support for the metadata removal
1 Support for the metadata removal
cox Starting horizontal coordinate of the cropping No Centered cropping This parameter is used along with the parameter cut and fixed. When starting horizontal coordinate of the cropping is not set, the centered cropping is used by default
coy Starting vertical coordinate of the cropping No Centered cropping This parameter is used along with the parameter cut and fixed. When starting vertical coordinate of the cropping is not set, the centered cropping is used by default
rotate Rotation angle No 0 1-360 The image is not rotated by default. To customize the rotation angle, you must specify the parameter <r> is 2
et Add the background No 0 0Not add
1Fill the background of the image in the blank range after it is scaled
etw Specify the background width No Maximum width of the source image 1-4096 Unit: pixels (px). If you do not set eth or etw, maximum height and width of the source image is used by default to form a square; if you set only etw, the default height is the height of the source image
eth Specify the background height No Maximum height of the source image 1-4096 Unit: pixels (px). If you do not set eth or etw, maximum height and width of the source image is used by default to form a square; if you set only eth, the default width is the width of the source image
etc Specify the background color No FFFFFF Support RRGGBB format (for transparent color, it is "transparent", and transparent background color supports PNG and GIF format)
interlace Progressive display No 0 0This means the image is saved in generic jpg and jpeg format
1This means the image is saved in progressively displayed jpg and jpeg format
Request header

The request does not require to set special header.

Response:

Response header
Header name Mandatory Description
Content-Type Yes MIME type. When the operation succeeds, the image type is fixed as MIME: image/*, and when the operation fails, it is application/json
Response content:

If the request is handled successfully, binary image data will be returned.

Special error:
HttpCode Meaning
200 Successful operation
400 Wrong request message format
404 Resources not exist
500 Operation at the server side fails.
In case of this error, please contact us in time.

Example

Set the scaling width only, and scale the image proportionally as per the width:

The width is 200 px
http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&w=200

Sample image

Set the scaling height only, and scale the image proportionally as per the height:

The height is 200 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&h=200

Sample image

Set the width and height, and scale the image proportionally according to long side without setting to scale the image by short side:

The height is 200 px, and the width is 100 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&h=200&w=100&m=0

Sample image

Set the width and height, and scale the image proportionally according to short side when it is set to scale the image by short side:

The height is 200 px, the width is 100 px, and m is 1

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&h=200&w=100&m=1

示例图片

Scale-down in proportion:

Scale down the image to 1/4 of the source image in proportion.

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&p=25

示例图片

Proportional scale-up at specified width:

The height is 400 px, and so is 1

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&w=400&so=1

示例图片

Centered cropping means that after the image is scaled, perform the centered cropping to the part outside the predefined range:

The height is 30 px, and the width is 200 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&h=30&w=200&m=0&c=1

示例图片

The height is 200 px, and the width is 20 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&h=200&w=20&m=1&c=1

示例图片

Perform centered cropping according to the fixed width and height when the width and height are fixed:

The height is 100 px, and the width is 50 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&h=100&w=50&c=1&f=1

示例图片

Cropping at any position means the cropping by setting the starting horizontal ordinate and starting vertical ordinate which must be within the image:

Starting horizontal ordinate is 100, starting vertical ordinate is 50, the cropping height is 200 px, and the width is 100 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&w=100&h=200&c=1&f=1&cox=100&coy=50

示例图片

Scale down the image to 100x100 as per long side, and then fill in red color:

The background height is 100 px, the background width is 100 px, and the image width (long side) is 100 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/s[email protected]@tag=imgscale&m=0&w=100&et=1&eth=100&etw=100&etc=FF0000

1.png

Crop an incircle in the image at a radius of 100 and convert it to png format:

Incircle radius of the image is 100 px

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgCircle&i=100&F=png

suiyi.png

Progressive display:

Specify the presentation that is fuzzy first and then clear for the image in jpg or jpeg format

http://ks3-cn-beijing.ksyun.com/ks3-resources/[email protected]@tag=imgScale&interlace=1

suiyi.png

Did you find the above information helpful?

Unhelpful
Mostly Unhelpful
A little helpful
Helpful
Very helpful

What might be the problems?

  • Insufficient
  • Outdated
  • Unclear or awkward
  • Redundant or clumsy
  • Lack of context for the complex system or functionality

More suggestions

0/200

Please give us your feedback.

Submitted

Thank you for your feedback.

问题反馈