Watermark

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

Image Processing


Watermark

Interface

imgWaterMarker

Description

Kingsoft Cloud provides three watermarking functions, including the text watermark, image watermark and mixed watermarks. If you have the read permission to the image file, you can add a watermark to the image.
By adding the watermark, you can make a personalized image or identify the source and copyright information of the image.

Description

1. 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.

 2. Image watermark

The watermark source image URL supports the HTTP protocol only currently. If you use HTTPS, the status code 400 error message will be returned.

Request:

Text watermark

Syntax

Notes: The interface format does not contain any space and line break. The following content has been formatted for easy reading.

https://BucketName.${domain name of the region where the bucket is located}/[email protected]@
	tag=imgWaterMarker
	&type=2
	&text=<base64EncodeText>
	&font=<base64EncodeFont>
	&fontsize=<base64EncodeFontSize>
	&fill=<base64EncodeFill>
	&dissolve=<dissolve>
	&gravity=<gravity>
	&dx=<offsetX>
	&dy=<offsetY>   HTTP/1.1
Host: BucketName.${domain name of the region where the bucket is located}
Request parameters
Parameter name Mandatory Explanation
tag Yes Operation flag
type Yes type=2 Text watermark
text Yes Watermark text (base64EncodeText, URL secured Base64 encode)
font No Text watermark font (base64EncodeFont, URL secured Base64 encode). The default is bold
fontsize No Font size (integer) in twips (1 twip=1/20 pound). The default is 500
fill No Text watermark color (base64EncodeFill, URL secured Base64 encode). This can be RGB format, or the color name (for example: black), or hexadecimal (for example: ## FF0000). Refer to RGB table
dissolve Non-transparency. The value range is 1~100, and the default value is 100. 100 indicates complete non-transparency.
gravity Watermark position. Refer to the following watermark anchor parameter table. The default value is SouthEast (at the bottom right side).
dx Horizontal axis (x axis) margin in pixels (px). The default value is 10
dy Vertical axis (y axis) margin in pixels (px). The default value is 10
q No Determine the relative quality of the jpg image and compress the source image.The value range is 0~100. 0 indicates high compression ratio and low quality, and 100 indicates low compression ratio and high quality. The default value is 90
Watermark anchor parameter list
NorthWest North NorthEast
West Center East
SouthWest South SouthEast
Request header

The request does not require to set special header.

Image watermark

Syntax

Notes: The interface format does not contain any space and line break. The following content has been formatted for easy reading.

https://BucketName.ks3-cn-beijing.ksyun.com/[email protected]@
	tag=imgWaterMark  
	&type=1  
	&dissolve=<dissolve>  
	&gravity=<gravity>  
	&image=<base64EncodeImageURI>  
	&dx=<offsetX>  
	&dy=<offsetY>
	&wtw=<width>
	&wth=<height>   HTTP/1.1
Host: BucketName.ks3-cn-beijing.ksyun.com
Request parameters
Parameter name Mandatory Explanation
tag Yes Operation flag
type Yes type=1, meaning the image watermark
image Yes Watermark source image URL (base64EncodeImageURI, URL secured Base64 encode). You must ensure this URL will return an image
dissolve Non-transparency. The value range is 1~100, and the default value is 100. 100 indicates complete non-transparency.
gravity Watermark position. Refer to the following watermark anchor parameter table. The default value is SouthEast (at the bottom right side).
dx Horizontal axis (x axis) margin in pixels (px). The default value is 10
dy Vertical axis (y axis) margin in pixels (px). The default value is 10
q No Determine the relative quality of the jpg image and compress the source image. The value range is 0~100. 0 indicates high compression ratio and low quality, and 100 indicates low compression ratio and high quality. The default value is 90
wtw No Watermark width threshold. If it is less than this value, the image will not be watermarked. The unit is pixels (px), and its range is the integer greater than 0
wth No Watermark height threshold. If it is less than this value, the image will not be watermarked. The unit is pixels (px), and its range is the integer greater than 0
Watermark anchor parameter list
NorthWest North NorthEast
West Center East
SouthWest South SouthEast
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.

  • If the request is not handled successfully, the content in the following JSON format will be returned:

      {
      	"errorCode": <HttpCode int>,
      	"tipInfo": <ErrorTipInfo String>,
      }
    
Special error
HTTP status code Meaning
400 Wrong request message format
404 Resources not exist
403 Access denied
500 Operation at the server side fails.

Example

Some simple examples about the watermarking function

Text watermark example
Sample request
  • Watermark text: Kingsoft Cloud
    • Original watermark text=Kingsoft Cloud
    • Encrypted watermark text (base64)=6YeR5bGx5LqR
    • text=6YeR5bGx5LqR
  • Watermark text font: Microsoft YaHei
    • Original text font=Microsoft YaHei
    • Encrypted watermark font (base64)=5b6u6L2v6ZuF6buR
    • font=5b6u6L2v6ZuF6buR
  • Watermark text color:## bf1717(Red)
    • Original font color=## bf1717
    • Encrypted font color (base64)=I2JmMTcxNw==
    • fill=I2JmMTcxNw==
  • Watermark font size: 500 (twips)
    • fontsize=500
    • Watermark location: upper right corner
    • gravity=NorthEast
  • Watermark non-transparency: 65%
    • dissolve=65
  • Horizontal axis margin: 10
    • dx=10
  • Vertical axis margin: 10
    • dy=10
Request code

Notes: The interface format does not contain any space and line break. The following content has been formatted for easy reading.

https://ks3-cn-beijing.ksyun.com/ks3/image_deal/[email protected]@
	tag=imgWaterMark
	&type=2
	&dissolve=65
	&gravity=NorthEast
	&text=6YeR5bGx5LqR
	&font=5b6u6L2v6ZuF6buR
	&fill=I2JmMTcxNw==
	&fontsize=500
	&dy=10
	&dx=20
Response sample

Sample text watermark

Sample image watermark
Sample request
Request code

Notes:

  • The interface format does not contain any space and line break. The following content has been formatted for easy reading.
  • When you make the image watermark, please note that the encrypted watermark link must start with http, otherwise, a 400 error message will be returned.
https://ks3-cn-beijing.ksyun.com/ks3/image_deal/[email protected]@
	tag=imgWaterMark   
	&type=1   
	&dissolve=65   
	&gravity=NorthEast   
	&image=aHR0cDovL2tzMy5rc3l1bi5jb20vY3NzL2ltZy9maXhlZF9rc2NfbG9nby5wbmc=   
	&dy=10   
	&dx=10   
Sample response

Sample image watermark

Sample mixed watermark
Sample request

Mixed watermark means you can perform two or more operations (basic image operation and image watermark) on the same image. Two operations need only to be separated with |.

  • The width is 200 px, and the height is 150 px
  • Watermark link:
    http://ks3.ksyun.com/css/img/fixed_ksc_logo.png
  • Watermark location: lower right corner
    • gravity=SouthEast
  • Watermark non-transparency: 65%
    • dissolve=65
  • Horizontal axis margin: 10
    • dx=10
  • Vertical axis margin: 10
    • dy=10
Request code

Notes:

  • The interface format does not contain any space and line break. The following content has been formatted for easy reading.
  • When you make the image watermark, please note that the encrypted watermark link must start with http, otherwise, a 400 error message will be returned.
https://ks3-cn-beijing.ksyun.com/ks3/image_deal/[email protected]@
	tag=imgBaseOp   
	&mode=0   
	&h=160   
	&w=220   
	|tag=imgWaterMark   
	&type=1   
	&dissolve=65   
	&gravity=NorthEast   
	&image=aHR0cDovL2tzMy5rc3l1bi5jb20vY3NzL2ltZy9maXhlZF9rc2NfbG9nby5wbmc=   
	&dy=10   
	&dx=10
    |tag=imgWaterMark   
    &type=1   
    &dissolve=65   
    &gravity=SouthEast   
    &image=aHR0cDovL2tzMy5rc3l1bi5jb20vY3NzL2ltZy9maXhlZF9rc2NfbG9nby5wbmc=   
    &dy=10   
    &dx=10   
Sample response

Sample mixed watermark

Sample image watermark threshold
Sample request
  • Watermark link:
    http://ks3.ksyun.com/css/img/fixed_ksc_logo.png
  • Watermark location: upper right corner
    • gravity=NorthEast
  • Watermark non-transparency: 65%
    • dissolve=65
  • Horizontal axis margin: 10
    • dx=10
  • Vertical axis margin: 10
    • dy=10
  • Width threshold: 500
    • wtw=500
  • Height threshold: 500
    • wth=500
Request code

Notes:

  • The interface format does not contain any space and line break. The following content has been formatted for easy reading.
  • When you make the image watermark, please note that the encrypted watermark link must start with http, otherwise, a 400 error message will be returned.
https://ks3-cn-beijing.ksyun.com/ks3/image_deal/[email protected]@
	tag=imgWaterMark   
	&type=1   
	&dissolve=65   
	&gravity=NorthEast   
	&image=aHR0cDovL2tzMy5rc3l1bi5jb20vY3NzL2ltZy9maXhlZF9rc2NfbG9nby5wbmc=   
	&dy=10   
	&dx=10
	&wtw=500
	&wth=500   
Sample response

Sample image watermark

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.

问题反馈