-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
568 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
LazZiya.ImageResize/Animated/AnimatedImageAnimatedTextWatermark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Net.Http.Headers; | ||
|
||
namespace LazZiya.ImageResize.Animated | ||
{ | ||
/// <summary> | ||
/// Add animated text watermark over animated image. | ||
/// </summary> | ||
public static class AnimatedImageAnimatedTextWatermark | ||
{ | ||
/// <summary> | ||
/// Add animated text watermark over animated image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text"></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this AnimatedImage img, string text) | ||
{ | ||
return AddAnimatedTextWatermark(img, text, new TextWatermarkOptions(), new AnimatedTextWatermarkOptions()); | ||
} | ||
|
||
/// <summary> | ||
/// Add animated text watermark over animated image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text"></param> | ||
/// <param name="animOps"></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this AnimatedImage img, string text, AnimatedTextWatermarkOptions animOps) | ||
{ | ||
return AddAnimatedTextWatermark(img, text, new TextWatermarkOptions(), animOps); | ||
} | ||
|
||
/// <summary> | ||
/// Add animated text watermark over animated image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text">text to draw over the image</param> | ||
/// <param name="ops">Text watermark options <see cref="TextWatermarkOptions"/></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this AnimatedImage img, string text, TextWatermarkOptions ops) | ||
{ | ||
return AddAnimatedTextWatermark(img, text, ops, new AnimatedTextWatermarkOptions()); | ||
} | ||
|
||
/// <summary> | ||
/// Add animated text watermark over animated image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text">text to draw over the image</param> | ||
/// <param name="ops">Text watermark options <see cref="TextWatermarkOptions"/></param> | ||
/// <param name="animOps">Animated text options <see cref="AnimatedTextWatermarkOptions"/></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this AnimatedImage img, string text, TextWatermarkOptions ops, AnimatedTextWatermarkOptions animOps) | ||
{ | ||
var fList = new List<Image>(); | ||
|
||
var charPerFrame = img.FramesCount >= text.Length ? 1 : text.Length / img.FramesCount; | ||
|
||
for (int i = 0; i < img.FramesCount; i++) | ||
{ | ||
var subLength = charPerFrame * i > text.Length ? text.Length : charPerFrame * i; | ||
var subStr = text.Substring(0, subLength); | ||
var frame = img.Frames[i].AddTextWatermark(subStr, ops); | ||
fList.Add(frame); | ||
} | ||
|
||
img.Frames.Clear(); | ||
img.Frames = fList; | ||
|
||
return img; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
LazZiya.ImageResize/Animated/AnimatedTextWatermarkOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace LazZiya.ImageResize.Animated | ||
{ | ||
/// <summary> | ||
/// Define options for animated text | ||
/// </summary> | ||
public class AnimatedTextWatermarkOptions | ||
{ | ||
/// <summary> | ||
/// Pre-defined text animations | ||
/// </summary> | ||
public TextAnimation TextAnimation { get; set; } = TextAnimation.Typing; | ||
} | ||
|
||
/// <summary> | ||
/// Pre defined text animations | ||
/// </summary> | ||
public enum TextAnimation | ||
{ | ||
/// <summary> | ||
/// increment char-by-char | ||
/// </summary> | ||
Typing = 0 | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
LazZiya.ImageResize/Animated/ImageAnimatedImageWatermark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
|
||
namespace LazZiya.ImageResize.Animated | ||
{ | ||
|
||
/// <summary> | ||
/// Add an animated image watermark to static image | ||
/// </summary> | ||
public static class ImageAnimatedImageWatermark | ||
{ | ||
/// <summary> | ||
/// Draw animated image watermark over a static image | ||
/// </summary> | ||
/// <param name="img">The original image</param> | ||
/// <param name="wmImgPath">Path to the watermark image file e.g. wwwroot\images\watermark.png</param> | ||
public static AnimatedImage AddAnimatedImageWatermark(this Image img, string wmImgPath) | ||
{ | ||
var wm = AnimatedImage.FromFile(wmImgPath); | ||
return img.AddAnimatedImageWatermark(wm, new ImageWatermarkOptions()); | ||
} | ||
|
||
/// <summary> | ||
/// Draw animated image watermark over a static image | ||
/// </summary> | ||
/// <param name="img">The original image</param> | ||
/// <param name="wmImage">Watermark image</param> | ||
public static AnimatedImage AddAnimatedImageWatermark(this Image img, AnimatedImage wmImage) | ||
{ | ||
return img.AddAnimatedImageWatermark(wmImage, new ImageWatermarkOptions()); | ||
} | ||
|
||
/// <summary> | ||
/// Draw animated image watermark over a static image | ||
/// </summary> | ||
/// <param name="img">The original image</param> | ||
/// <param name="wmImgPath">Path to the watermark image file e.g. wwwroot\images\watermark.png</param> | ||
/// <param name="ops">Image watermark options <see cref="ImageWatermarkOptions"/></param> | ||
public static AnimatedImage AddAnimatedImageWatermark(this Image img, string wmImgPath, ImageWatermarkOptions ops) | ||
{ | ||
var wm = AnimatedImage.FromFile(wmImgPath); | ||
return img.AddAnimatedImageWatermark(wm, ops); | ||
} | ||
|
||
/// <summary> | ||
/// Draw animated image watermark over a static image | ||
/// <para>Notice regarding watermark opacity:</para> | ||
/// <para>If watermark image needs to be resized, first resize the watermark image, | ||
/// then save it to the disc, and read it again with Image.FromFile.</para> | ||
/// </summary> | ||
/// <param name="img">The original image</param> | ||
/// <param name="wmImage">Watermak image</param> | ||
/// <param name="ops">Image watermark options <see cref="ImageWatermarkOptions"/></param> | ||
public static AnimatedImage AddAnimatedImageWatermark(this Image img, AnimatedImage wmImage, ImageWatermarkOptions ops) | ||
{ | ||
var fList = new List<Image>(); | ||
var animImg = new AnimatedImage(new[] { img }); | ||
|
||
for (int i = 0; i < wmImage.FramesCount; i++) | ||
{ | ||
var clone = img.Clone() as Image; | ||
var imgI = clone.AddImageWatermark(wmImage.Frames[i], ops, false); | ||
fList.Add(imgI); | ||
} | ||
|
||
img.Dispose(); | ||
wmImage.Dispose(); | ||
|
||
//animImg.Frames?.Clear(); | ||
animImg.Frames = fList; | ||
|
||
return animImg; | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
LazZiya.ImageResize/Animated/ImageAnimatedTextWatermark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
|
||
namespace LazZiya.ImageResize.Animated | ||
{ | ||
/// <summary> | ||
/// Add animated text watermark over image | ||
/// </summary> | ||
public static class ImageAnimatedTextWatermark | ||
{ | ||
/// <summary> | ||
/// Add animated text watermark over a static image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text"></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this Image img, string text) | ||
{ | ||
return AddAnimatedTextWatermark(img, text, new TextWatermarkOptions(), new AnimatedTextWatermarkOptions()); | ||
} | ||
|
||
/// <summary> | ||
/// Add animated text watermark over a static image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text"></param> | ||
/// <param name="animOps"></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this Image img, string text, AnimatedTextWatermarkOptions animOps) | ||
{ | ||
return AddAnimatedTextWatermark(img, text, new TextWatermarkOptions(), animOps); | ||
} | ||
|
||
/// <summary> | ||
/// Add animated text watermark over a static image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text">text to draw over the image</param> | ||
/// <param name="ops">Text watermark options <see cref="TextWatermarkOptions"/></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this Image img, string text, TextWatermarkOptions ops) | ||
{ | ||
return AddAnimatedTextWatermark(img, text, ops, new AnimatedTextWatermarkOptions()); | ||
} | ||
|
||
/// <summary> | ||
/// Add animated text watermark over a static image. | ||
/// </summary> | ||
/// <param name="img"></param> | ||
/// <param name="text">text to draw over the image</param> | ||
/// <param name="ops">Text watermark options <see cref="TextWatermarkOptions"/></param> | ||
/// <param name="animOps">Animated text options <see cref="AnimatedTextWatermarkOptions"/></param> | ||
public static AnimatedImage AddAnimatedTextWatermark(this Image img, string text, TextWatermarkOptions ops, AnimatedTextWatermarkOptions animOps) | ||
{ | ||
var fList = new List<Image>(); | ||
var animImg = new AnimatedImage(new List<Image> { img }); | ||
|
||
for (int i = 0; i < text.Length; i++) | ||
{ | ||
var subStr = text.Substring(0, i); | ||
var clone = img.Clone() as Image; | ||
var frame = clone.AddTextWatermark(subStr, ops); | ||
fList.Add(frame); | ||
} | ||
|
||
img.Dispose(); | ||
|
||
animImg.RepeatCount = 0; | ||
animImg.Frames = fList; | ||
|
||
return animImg; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.