百度智能云

All Product Document

          Object Storage

          Watermark

          Overview

          This article describes how to set the watermark. Photo watermark refers to insert another photo or text above the photo as a watermark, which is a means of digital information protection. Currently, the BOS photo processing V1.0 protocol supports two watermarking methods: photo watermarking and text watermarking. BOS divides your original photo into 9 areas as shown in the figure below, and number them according to the position of the photo. Each area contains anchor points.

          If required to determine the final position of the watermark on the original photo, you need to determine the following two factors:

          • Position of the anchor;
          • Designate the distance in the horizontal and vertical directions based on the location of anchor.

          The anchor position is as shown in the figure:

          BOS8.png

          Watermark Parameters of Photos


          Parameter name Resizing command Type Value range Request description Default value Is it required
          watermark wm unsigned 0,1,2 Designate the method of making watermark.
          wm_0 means the watermark feature is disabled;
          wm_1 means photo watermark;
          wm_2 means text watermark.
          - Yes
          key k string - Designate the
          Object name of the watermark photo stored on BOS, that is, ObjectKey.
          If the Object is stored in a folder,
          you need to include the folder path.
          This is required to be the value after Base64 encoding.
          - Yes
          gravity g unsigned int 1~9 Designate the anchor location for the watermark.
          Please refer to [command of photo watermark](#Command of Photo Watermark) for the meaning of photo anchor.
          9 No
          gravityX x int -4096~4096 Designate the horizontal distance of the watermark based on the anchor. 10 No
          gravityY y int -4096~4096 Designate the vertical distance of the watermark based on the anchor. 10 No
          angle a int -360~360 Designate the rotation angle of the the photo with watermark.
          The positive number indicates clockwise rotation, such as a_60; while the
          negative number indicates counterclockwise rotation, such as a_-30.
          0 No
          opacity o unsigned int 1~100 Designate the transparency of the the photo with watermark.
          When the value is 100, it means that the transparency of that of the original
          photo is the same.
          100 No

          Note

          • The photo with watermark and the original photo should be stored in the same Bucket of BOS.

          Parameters of Text Watermark


          Parameter name Resizing command Type Value range Request description Default value Is it required
          watermark wm unsigned 0,1,2 Designate the method of making watermark.
          wm_0 means the watermark feature is disabled;
          wm_1 means photo watermark;
          wm_2 means text watermark.
          - Yes
          text t string - The text watermark needs to be encoded with
          Base64, and the maximum number of characters after encoding should be no more than 80.
          - Yes
          gravity g unsigned
          int
          1~9 Designate the anchor location for the watermark. Please refer to [command of photo watermark](#Command of Photo Watermark) for the meaning of photo
          anchor.
          9 No
          gravityX x int -4096~4096 Designate the distance of horizontal distance
          of the watermark based on the anchor.
          10 No
          gravityY y int -4096~4096 Designate the distance of vertical distance
          of the watermark based on the anchor.
          10 No
          angle a int -360~360 Designate the rotation angle of the the photo with watermark.
          The positive number indicates clockwise rotation, such as
          a_60; while the
          negative number indicates counterclockwise rotation, such as
          a_-30.
          0 No
          fontSize sz unsigned
          int
          1~1024 Designate the font size of watermark, which is
          in px.
          30 No
          fontColor fc string - Designate the font color as an 8-bit
          hexadecimal string, where every 2
          bits are used to represent an item in RGBA.
          The first six bits represent RGB color respectively, such as
          ffffff; while the last two bits represent the Alpha
          channel, which can be omitted, and when omitted, it refers to
          opaque.
          E.g.: 000000ff refers to the black
          opaque font.
          000000 No
          fontFamily ff string - Designate the font type of the font, select the value
          , and conduct Base64 encoding. See the list
          below for supported
          font types.
          Song typeface No
          fontStyle fs string normal( Conventional)
          italic( Italic)
          bold( Bold)
          Designate the font style. normal No

          The supported font types:

          Parameter value Font type
          MicrosoftYaHei Microsoft YaHei
          FangSong Imitation Song-Dynasty-style typeface
          SimHei Blackbody
          KaiTi Regular script
          SimSun Song typeface
          FZBeiWeiKaiShuJianTi Founder simplified regular script of the Northern Wei Dynasty
          FZBoYaSongJianTi Founder simplified Song-Dynasty-style typeface
          FZCuHeiSongJianTi Founder simplified Song-Dynasty-style bold black
          FZLanTingZhongHeiJianTi Founder Lanting simplified black typeface
          FZZhengHei Founder JhengHei
          AvantGarde AvantGarde
          Bookman Bookman
          Courier Courier
          Helvetica Helvetica
          HelveticaNarrow HelveticaNarrow
          NewCenturySchlbk NewCenturySchlbk
          Palatino Palatino
          Times Times
          Symbol Symbol

          Note

          • Text effects are rendered only if the fontfamily supports the FontStyle effect.
          • If the specified font style is not included in the currently supported fontfamily list, the default font should be Song typeface.

          The Mixed Photo and Text Watermark

          The mixed photo and text watermark refers to print the photo watermark and text watermark on the original photo at the same time. Since the photo watermark and text watermark are two independent commands, the mixed photo and text watermark needs to be implemented by pipeline.

          Example

          Photo watermark example

          The original photo is image.jpg, and the photo with watermark is bce-documentation/BOS/bce.jpg (Base64 is encoded as “YmNlLWRvY3VtZW50YXRpb24vQk9TL2JjZS5qcGc=”).

          • Add the photo watermark in the lower right corner, and designate the vertical distance of 10 and the transparency of 60.

          https://doc.bce.baidu.com/bce-documentation/BOS/image.jpg@wm_1,k_YmNlLWRvY3VtZW50YXRpb24vQk9TL2JjZS5qcGc=,y_10,o_60

          • Add the watermark in the lower left corner, determine the default values as horizontal and vertical distances, specify the transparency of 50, and rotate 90 degrees clockwise.

          https://doc.bce.baidu.com/bce-documentation/BOS/image.jpg@wm_1,k_YmNlLWRvY3VtZW50YXRpb24vQk9TL2JjZS5qcGc=,g_7,o_50,a_90

          Text watermark example

          • The text watermark is the simplest, and the text content is “hello world”.

          https://doc.bce.baidu.com/bce-documentation/BOS/image.jpg@wm_2,t_aGVsbG8gd29ybGQ=

          • The text content is “hello world”, the font type is Microsoft YaHei, the font color and font size are defaulted, the font style is bold, the watermark position is in the middle right, the horizontal distance from the anchor point is 20, the vertical distance is 20, and the clockwise rotation is 30 degrees.

          https://doc.bce.baidu.com/bce-documentation/BOS/image.jpg@wm_2,t_aGVsbG8gd29ybGQ=,ff_TWljcm9zb2Z0WWFIZWk=,fs_bold,g_6,x_20,y_20,a_30

          The mixed photo and text watermark

          • The simplest mixed photo and text watermark The photo is in the form of bce-documentation/BOS/bce.jpg, the text content is “hello world”, and the other parameters are all default value.

          https://doc.bce.baidu.com/bce-documentation/BOS/image.jpg@wm_1,k_YmNlLWRvY3VtZW50YXRpb24vQk9TL2JjZS5qcGc=|wm_2,t_aGVsbG8gd29ybGQ=

          • The mixed photo and text watermark The watermark photo is in the form of bce-documentation/BOS/bce.jpg, which is located at the lower left corner of the original photo with the horizontal distance from the anchor point of 15, the vertical distance of 20, and the transparency of 50; the text content is “hello world”, which is located at the top with the vertical distance of 100, and the font color is lavender.

          https://doc.bce.baidu.com/bce-documentation/BOS/image.jpg@wm_1,k_YmNlLWRvY3VtZW50YXRpb24vQk9TL2JjZS5qcGc=,g_7,x_15,y_20,o_50|wm_2,t_aGVsbG8gd29ybGQ=,g_2,y_100,fc_aa88aa_100, fc_aa88aa>

          Previous
          Quality Transformation
          Next
          Get Photo Information