|
1 | 1 | using System; |
2 | 2 | using System.Text; |
3 | | -using Qiniu.Util; |
4 | | - |
5 | | -namespace Qiniu.FileOp |
6 | | -{ |
7 | | - public class TextWaterMarker:WaterMarker |
8 | | - { |
9 | | - public string text; |
10 | | - private string fontName; |
11 | | - private int fontSize; |
12 | | - private string color; |
13 | | - |
14 | | - public TextWaterMarker (string text, string fontname = "", string color = "", int fontsize = 0, int dissolve = 50, MarkerGravity gravity = MarkerGravity.SouthEast, int dx = 10, int dy = 10) |
15 | | - : base(dissolve,gravity, dx, dy) |
16 | | - { |
17 | | - this.text = text; |
18 | | - this.fontName = fontname; |
19 | | - this.fontSize = fontsize; |
20 | | - this.color = color; |
21 | | - } |
22 | | - |
23 | | - public override string MakeRequest (string url) |
24 | | - { |
25 | | - StringBuilder sb = new StringBuilder (); |
26 | | - sb.Append (string.Format ("{0}?watermark/{1}", url, 2)); |
27 | | - if (string.IsNullOrEmpty (text)) { |
28 | | - throw new Exception ("No Text To Draw"); |
29 | | - } |
30 | | - sb.Append ("/text/" + text.ToBase64URLSafe ()); |
31 | | - |
32 | | - if (!string.IsNullOrEmpty (fontName)) { |
33 | | - sb.Append ("/font/" + fontName.ToBase64URLSafe ()); |
34 | | - } |
35 | | - if (fontSize > 0) { |
36 | | - sb.Append ("/fontsize/" + fontSize); |
37 | | - } |
38 | | - if (!string.IsNullOrEmpty (color)) { |
39 | | - sb.Append ("/fill/" + color.ToBase64URLSafe ()); |
40 | | - } |
41 | | - sb.Append ("/dissolve/" + dissolve); |
42 | | - sb.Append ("/gravity/" + Gravitys [(int)gravity]); |
43 | | - sb.Append ("/dx/" + dx); |
44 | | - sb.Append ("/dy/" + dy); |
45 | | - return sb.ToString (); |
46 | | - } |
47 | | - } |
| 3 | +using Qiniu.Util; |
| 4 | + |
| 5 | +namespace Qiniu.FileOp |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// |
| 9 | + /// </summary> |
| 10 | + public class TextWaterMarker : WaterMarker |
| 11 | + { |
| 12 | + private string text; |
| 13 | + private string fontName; |
| 14 | + private int fontSize; |
| 15 | + private string color; |
| 16 | + |
| 17 | + public TextWaterMarker(string text, string fontname = "", string color = "", int fontsize = 0, int dissolve = 50, MarkerGravity gravity = MarkerGravity.SouthEast, int dx = 10, int dy = 10) |
| 18 | + : base(dissolve, gravity, dx, dy) |
| 19 | + { |
| 20 | + this.text = text; |
| 21 | + this.fontName = fontname; |
| 22 | + this.fontSize = fontsize; |
| 23 | + this.color = color; |
| 24 | + } |
| 25 | + |
| 26 | + public override string MakeRequest(string url) |
| 27 | + { |
| 28 | + StringBuilder sb = new StringBuilder(); |
| 29 | + sb.Append(string.Format("{0}?watermark/{1}", url, 2)); |
| 30 | + if (string.IsNullOrEmpty(text)) |
| 31 | + { |
| 32 | + throw new Exception("No Text To Draw"); |
| 33 | + } |
| 34 | + sb.Append("/text/" + Base64URLSafe.ToBase64URLSafe(text)); |
| 35 | + |
| 36 | + if (!string.IsNullOrEmpty(fontName)) |
| 37 | + { |
| 38 | + sb.Append("/font/" + Base64URLSafe.ToBase64URLSafe(fontName)); |
| 39 | + } |
| 40 | + if (fontSize > 0) |
| 41 | + { |
| 42 | + sb.Append("/fontsize/" + fontSize); |
| 43 | + } |
| 44 | + if (!string.IsNullOrEmpty(color)) |
| 45 | + { |
| 46 | + sb.Append("/fill/" + Base64URLSafe.ToBase64URLSafe(color)); |
| 47 | + } |
| 48 | + sb.Append("/dissolve/" + dissolve); |
| 49 | + sb.Append("/gravity/" + Gravitys[(int)gravity]); |
| 50 | + sb.Append("/dx/" + dx); |
| 51 | + sb.Append("/dy/" + dy); |
| 52 | + return sb.ToString(); |
| 53 | + } |
| 54 | + } |
48 | 55 | } |
0 commit comments