Skip to content

Commit

Permalink
conditional text, image watermark methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LazZiya committed Mar 9, 2021
1 parent 346e322 commit ce03daf
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace LazZiya.ImageResize.Animated
{
/// <summary>
/// Add animated text watermark over animated image, depending on a condition parameter.
/// </summary>
public static class AnimatedImageAnimatedTextWatermarkConditional
{
/// <summary>
/// Add animated text watermark over animated image, depending on a conditon parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the img</param>
/// <param name="text"></param>
public static AnimatedImage AddAnimatedTextWatermarkIf(this AnimatedImage img, bool condition, string text)
{
return condition ? AnimatedImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text) : img;
}

/// <summary>
/// Add animated text watermark over animated image, depending on a conditon parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the img</param>
/// <param name="text"></param>
/// <param name="animOps"></param>
public static AnimatedImage AddAnimatedTextWatermarkIf(this AnimatedImage img, bool condition, string text, AnimatedTextWatermarkOptions animOps)
{
return condition ? AnimatedImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text, animOps) : img;
}

/// <summary>
/// Add animated text watermark over animated image, depending on a conditon parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the 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 AddAnimatedTextWatermarkIf(this AnimatedImage img, bool condition, string text, TextWatermarkOptions ops)
{
return condition ? AnimatedImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text, ops) : img;
}

/// <summary>
/// Add animated text watermark over animated image, depending on a conditon parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the 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 AddAnimatedTextWatermarkIf(this AnimatedImage img, bool condition, string text, TextWatermarkOptions ops, AnimatedTextWatermarkOptions animOps)
{
return condition ? AnimatedImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text, ops, animOps) : img;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Drawing;

namespace LazZiya.ImageResize.Animated
{
/// <summary>
/// Add a static image watermark over animated image, depending on a condition parameter.
/// </summary>
public static class AnimatedImageImageWatermarkConditional
{
/// <summary>
/// Add a static image watermark over animated image, depending on a condition parameter.
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add image watermark, false will return the img</param>
/// <param name="wmImgPath">Path to the watermark image file e.g. wwwroot\images\watermark.png</param>
public static AnimatedImage AddImageWatermarkIf(this AnimatedImage img, bool condition, string wmImgPath)
{
return condition ? AnimatedImageImageWatermark.AddImageWatermark(img, wmImgPath) : img;
}

/// <summary>
/// Add a static image watermark over animated image, depending on a condition parameter.
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add image watermark, false will return the img</param>
/// <param name="wmImage">Watermark image</param>
public static AnimatedImage AddImageWatermarkIf(this AnimatedImage img, bool condition, Image wmImage)
{
return condition ? AnimatedImageImageWatermark.AddImageWatermark(img, wmImage) : img;
}

/// <summary>
/// Add a static image watermark over animated image, depending on a condition parameter.
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add image watermark, false will return the img</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 AddImageWatermarkIf(this AnimatedImage img, bool condition, string wmImgPath, ImageWatermarkOptions ops)
{
return condition ? AnimatedImageImageWatermark.AddImageWatermark(img, wmImgPath, ops) : img;
}

/// <summary>
/// Add a static image watermark over animated image, depending on a condition parameter.
/// <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="condition">true to add image watermark, false will return the img</param>
/// <param name="wmImage">Watermak image</param>
/// <param name="ops">Image watermark options <see cref="ImageWatermarkOptions"/></param>
public static AnimatedImage AddImageWatermarkIf(this AnimatedImage img, bool condition, Image wmImage, ImageWatermarkOptions ops)
{
return condition ? AnimatedImageImageWatermark.AddImageWatermark(img, wmImage, ops) : img;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using LazZiya.ImageResize.Animated;

namespace LazZiya.ImageResize
{
/// <summary>
/// Add a static text watermark over animated image, depending on a condition parameter
/// </summary>
public static class AnimatedImageTextWatermarkConditional
{
/// <summary>
/// Add a static text watermark over animated image depending on a condition parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the img</param>
/// <param name="text"></param>
public static AnimatedImage AddTextWatermarkIf(this AnimatedImage img, bool condition, string text)
{
return condition ? AnimatedImageTextWatermark.AddTextWatermark(img, text) : img;
}

/// <summary>
/// Add a static text watermark over animated image depending on a condition parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the 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 AddTextWatermarkIf(this AnimatedImage img, bool condition, string text, TextWatermarkOptions ops)
{
return condition ? AnimatedImageTextWatermark.AddTextWatermark(img, text, ops) : img;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Drawing;

namespace LazZiya.ImageResize.Animated
{

/// <summary>
/// Add an animated image watermark to static image adn return an AnimatedImage, depending on a condition parameter.
/// </summary>
public static class ImageAnimatedImageWatermarkConditional
{
/// <summary>
/// Draw animated image watermark over a static image, depending on a condition parameter.
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add animated image watermark, false will return the img as AnimatedImage</param>
/// <param name="wmImgPath">Path to the watermark image file e.g. wwwroot\images\watermark.png</param>
public static AnimatedImage AddAnimatedImageWatermarkIf(this Image img, bool condition, string wmImgPath)
{
return condition ? ImageAnimatedImageWatermark.AddAnimatedImageWatermark(img, wmImgPath) : new AnimatedImage(new[] { img });
}

/// <summary>
/// Draw animated image watermark over a static image, depending on a condition parameter.
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add animated image watermark, false will return the img as AnimatedImage</param>
/// <param name="wmImage">Watermark image</param>
public static AnimatedImage AddAnimatedImageWatermarkIf(this Image img, bool condition, AnimatedImage wmImage)
{
return condition ? ImageAnimatedImageWatermark.AddAnimatedImageWatermark(img, wmImage) : new AnimatedImage(new[] { img });
}

/// <summary>
/// Draw animated image watermark over a static image, depending on a condition parameter.
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add animated image watermark, false will return the img as AnimatedImage</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 AddAnimatedImageWatermarkIf(this Image img, bool condition, string wmImgPath, ImageWatermarkOptions ops)
{
return condition ? ImageAnimatedImageWatermark.AddAnimatedImageWatermark(img, wmImgPath, ops) : new AnimatedImage(new[] { img });
}

/// <summary>
/// Draw animated image watermark over a static image, depending on a condition parameter.
/// <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="condition">true to add animated image watermark, false will return the img as AnimatedImage</param>
/// <param name="wmImage">Watermak image</param>
/// <param name="ops">Image watermark options <see cref="ImageWatermarkOptions"/></param>
public static AnimatedImage AddAnimatedImageWatermarkIf(this Image img, bool condition, AnimatedImage wmImage, ImageWatermarkOptions ops)
{
return condition ? ImageAnimatedImageWatermark.AddAnimatedImageWatermark(img, wmImage, ops) : new AnimatedImage(new[] { img });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Drawing;

namespace LazZiya.ImageResize.Animated
{
/// <summary>
/// Add animated text watermark over image, depending on a conditional parameter.
/// </summary>
public static class ImageAnimatedTextWatermarkConditional
{
/// <summary>
/// Add animated text watermark over a static image, depending on a conditional parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add animated text watermark, false will return the img as AnimatedImage</param>
/// <param name="text"></param>
public static AnimatedImage AddAnimatedTextWatermarkIf(this Image img, bool condition, string text)
{
return condition ? ImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text) : new AnimatedImage(new[] { img });
}

/// <summary>
/// Add animated text watermark over a static image, depending on a conditional parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add animated text watermark, false will return the img as AnimatedImage</param>
/// <param name="text"></param>
/// <param name="animOps"></param>
public static AnimatedImage AddAnimatedTextWatermarkIf(this Image img, bool condition, string text, AnimatedTextWatermarkOptions animOps)
{
return condition ? ImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text, animOps) : new AnimatedImage(new[] { img });
}

/// <summary>
/// Add animated text watermark over a static image, depending on a conditional parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add animated text watermark, false will return the img as AnimatedImage</param>
/// <param name="text">text to draw over the image</param>
/// <param name="ops">Text watermark options <see cref="TextWatermarkOptions"/></param>
public static AnimatedImage AddAnimatedTextWatermarkIf(this Image img, bool condition, string text, TextWatermarkOptions ops)
{
return condition ? ImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text, ops) : new AnimatedImage(new[] { img });
}

/// <summary>
/// Add animated text watermark over a static image, depending on a conditional parameter.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add animated text watermark, false will return the img as AnimatedImage</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 AddAnimatedTextWatermarkIf(this Image img, bool condition, string text, TextWatermarkOptions ops, AnimatedTextWatermarkOptions animOps)
{
return condition ? ImageAnimatedTextWatermark.AddAnimatedTextWatermark(img, text, ops, animOps) : new AnimatedImage(new[] { img });
}
}
}
63 changes: 63 additions & 0 deletions LazZiya.ImageResize/ImageWatermarkConditional.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using LazZiya.ImageResize.Tools;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace LazZiya.ImageResize
{
/// <summary>
/// Draw image watermark depending on a conditional parameter
/// </summary>
public static class ImageWatermarkConditional
{

/// <summary>
/// Draw image watermark if the condition is true, otherwise return without image watermark
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add image watermark, false will return the img</param>
/// <param name="wmImgPath">Path to the watermark image file e.g. wwwroot\images\watermark.png</param>
public static Image AddImageWatermarkIf(this Image img, bool condition, string wmImgPath)
{
return condition ? ImageWatermark.AddImageWatermark(img, wmImgPath) : img;
}

/// <summary>
/// Draw image watermark if the condition is true, otherwise return without image watermark
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add image watermark, false will return the img</param>
/// <param name="wmImage">Watermark image</param>
public static Image AddImageWatermarkIf(this Image img, bool condition, Image wmImage)
{
return condition ? ImageWatermark.AddImageWatermark(img, wmImage) : img;
}

/// <summary>
/// Draw image watermark if the condition is true, otherwise return without image watermark
/// </summary>
/// <param name="img">The original image</param>
/// <param name="condition">true to add image watermark, false will return the img</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 Image AddImageWatermarkIf(this Image img, bool condition, string wmImgPath, ImageWatermarkOptions ops)
{
return condition ? ImageWatermark.AddImageWatermark(img, wmImgPath, ops) : img;
}

/// <summary>
/// Draw image watermark if the condition is true, otherwise return without image watermark
/// <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="condition">true to add image watermark, false will return the img</param>
/// <param name="wmImage">Watermak image</param>
/// <param name="ops">Image watermark options <see cref="ImageWatermarkOptions"/></param>
/// <param name="disposeWaterMark">Optional: dispose watermar image after finishing. Default: true</param>
public static Image AddImageWatermarkIf(this Image img, bool condition, Image wmImage, ImageWatermarkOptions ops, bool disposeWaterMark = true)
{
return condition ? ImageWatermark.AddImageWatermark(img, wmImage, ops, disposeWaterMark) : img;
}
}
}
34 changes: 34 additions & 0 deletions LazZiya.ImageResize/TextWatermarkConditional.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Drawing;

namespace LazZiya.ImageResize
{
/// <summary>
/// Add text watermark over the image depending on a conditional parameter.
/// </summary>
public static class TextWatermarkConditional
{

/// <summary>
/// Add a text watermark if the condition is true, otherwise return without textwatermark.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the img</param>
/// <param name="text"></param>
public static Image AddTextWatermarkIf(this Image img, bool condition, string text)
{
return condition ? TextWatermark.AddTextWatermark(img, text) : img;
}

/// <summary>
/// Add a text watermark if the condition is true, otherwise return without textwatermark.
/// </summary>
/// <param name="img"></param>
/// <param name="condition">true to add text watermark, false will return the img</param>
/// <param name="text">text to draw over the image</param>
/// <param name="ops">Text watermark options <see cref="TextWatermarkOptions"/></param>
public static Image AddTextWatermarkIf(this Image img, bool condition, string text, TextWatermarkOptions ops)
{
return condition ? TextWatermark.AddTextWatermark(img, text, ops) : img;
}
}
}

0 comments on commit ce03daf

Please sign in to comment.