Watermark

Add watermarks (text/image/mixed) to images to protect copyright and prevent unauthorized use. Supports custom watermark position, transparency, font, color, and tiling.

Function

  • Operation: watermark
  • URL pattern: ?x-oss-process=image/watermark,{param}_{value}[,...]
  • Supports text watermarks, image watermarks, and mixed watermarks
  • Supports watermark tiling
  • Key parameters (text / image) require Base64-URL-safe encoding

Parameters

Common parameters

ParamTypeRequiredDefaultRangeDescription
tIntegerNo100[0, 100] (%)Watermark transparency
gStringNoseNine-grid positionnw/north/ne/west/center/east/sw/south/se
xIntegerNo10[0, 4096] (px)Horizontal margin (only for left/right positions)
yIntegerNo10[0, 4096] (px)Vertical margin (only for top/bottom positions)
voffsetIntegerNo0[-1000, 1000] (px)Centerline vertical offset (only for middle row)
fillIntegerNo00 / 10:no tiling;1:tile across image
padxIntegerNo0[0, 4096] (px)Horizontal spacing when tiling (only with fill=1)
padyIntegerNo0[0, 4096] (px)Vertical spacing when tiling (only with fill=1)

Text watermark parameters

ParamTypeRequiredDefaultRangeDescription
textStringYesBase64-encoded stringText content (≤ 64 bytes before encoding)
typeStringNowqy-zenheiBase64-encoded font nameFont (e.g., wqy-zenhei)
colorStringNo0000006-digit RGB hexText color
sizeIntegerNo40(0, 1000] (px)Text size
shadowIntegerNo0[0, 100] (%)Text shadow transparency
rotateIntegerNo0[0, 360] (degrees)Clockwise rotation angle

Image watermark parameters

ParamTypeRequiredDefaultRangeDescription
imageStringYesBase64-encoded stringWatermark image Object path
PIntegerNo[1, 100] (%)Scale watermark proportionally to source image

[!IMPORTANT]

  • text and image must be Base64 URL-safe encoded
  • Image watermark can only use images in the same storage bucket
  • Maximum 3 different image watermarks per image

Code Examples

URL DSL

# Text watermark ("Hello": SGVsbG8)
?x-oss-process=image/watermark,text_SGVsbG8

# Image watermark (panda.png: cGFuZGEucG5n)
?x-oss-process=image/watermark,image_cGFuZGEucG5n

# Mixed text and image
?x-oss-process=image/watermark,image_cGFuZGEucG5n,text_SGVsbG8

# Tiled watermark
?x-oss-process=image/watermark,text_Q29weXJpZ2h0,fill_1

processImage (URL string)

import { processImage } from '@imgx-kit/core';

const buf = await processImage(
  './photo.jpg',
  'image/watermark,text_SGVsbG8',
);

imgx chain API

import { imgx } from '@imgx-kit/core';

// Text watermark
const buf1 = await imgx('./photo.jpg')
  .watermark({ text: 'SGVsbG8' })
  .toBuffer();

// Image watermark
const buf2 = await imgx('./photo.jpg')
  .watermark({ image: 'cGFuZGEucG5n' })
  .toBuffer();

// Mixed
const buf3 = await imgx('./photo.jpg')
  .watermark({ image: 'cGFuZGEucG5n', text: 'SGVsbG8' })
  .toBuffer();

// Tiling
const buf4 = await imgx('./photo.jpg')
  .watermark({ text: 'Q29weXJpZ2h0', fill: 1 })
  .toBuffer();

Edge Cases & Limits

  • text and image must be Base64 URL-safe encoded
  • text length limit 64 bytes before encoding
  • image must be in the same bucket
  • fill_1 is mutually exclusive with g / x / y
  • General size / pixel limits: see Getting Started