|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
using System.Globalization; |
|
|
|
|
using System.Numerics; |
|
|
|
|
using System.Text; |
|
|
|
|
using ICU4N.Text; |
|
|
|
|
using ImageMagick; |
|
|
|
|
using Kynareth.Models; |
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
@ -14,38 +16,63 @@ public static partial class ImageManager |
|
|
|
|
ConfigureManipulation(configuration, appEnvironment); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static ObjectResult GetResult(int statusCode, object data) |
|
|
|
|
=> new(data) { StatusCode = statusCode }; |
|
|
|
|
static BreakIterator lineBreakIterator = BreakIterator.GetLineInstance(CultureInfo.InvariantCulture); |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PositionRect rect, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
private static ObjectResult GetResult(int statusCode, object data) => new(data) { StatusCode = statusCode }; |
|
|
|
|
|
|
|
|
|
private static string GetText(string text) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"label:{text}", new MagickReadSettings() |
|
|
|
|
StringBuilder newText = new(); |
|
|
|
|
|
|
|
|
|
// set the text to be broken |
|
|
|
|
lineBreakIterator.SetText(text); |
|
|
|
|
|
|
|
|
|
// get the first boundary |
|
|
|
|
int start = lineBreakIterator.First(); |
|
|
|
|
|
|
|
|
|
// iterate over all boundaries |
|
|
|
|
for (int end = lineBreakIterator.Next(); end != BreakIterator.Done; start = end, end = lineBreakIterator.Next()) |
|
|
|
|
{ |
|
|
|
|
// get the current line |
|
|
|
|
string line = text.Substring(start, end - start); |
|
|
|
|
|
|
|
|
|
// do something with the line |
|
|
|
|
newText.AppendLine(line); |
|
|
|
|
Console.WriteLine(line); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return newText.ToString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PositionRect rect, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = rect.Width, |
|
|
|
|
Height = rect.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
|
StrokeColor = new MagickColor(strokeColor ?? MagickColors.Black), |
|
|
|
|
StrokeWidth = strokeWidth |
|
|
|
|
StrokeWidth = strokeWidth, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image.Composite(label, rect.X, rect.Y, CompositeOperator.Over); |
|
|
|
|
|
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PositionRect rect, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PositionRect rect, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = rect.Width, |
|
|
|
|
Height = rect.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
FontPointsize = fontSize, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
@ -58,15 +85,15 @@ public static partial class ImageManager |
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, Vector2 position, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, Vector2 position, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = image.Width, |
|
|
|
|
Height = image.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
|
StrokeColor = new MagickColor(strokeColor ?? MagickColors.Black), |
|
|
|
@ -78,15 +105,15 @@ public static partial class ImageManager |
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, Vector2 position, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, Vector2 position, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = image.Width, |
|
|
|
|
Height = image.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
FontPointsize = fontSize, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
@ -99,15 +126,15 @@ public static partial class ImageManager |
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PointD position, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PointD position, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = image.Width, |
|
|
|
|
Height = image.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
|
StrokeColor = new MagickColor(strokeColor ?? MagickColors.Black), |
|
|
|
@ -119,15 +146,15 @@ public static partial class ImageManager |
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PointD position, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PointD position, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = image.Width, |
|
|
|
|
Height = image.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
FontPointsize = fontSize, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
@ -140,15 +167,15 @@ public static partial class ImageManager |
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, int x, int y, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, int x, int y, MagickColor fontColor, Encoding encoding, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = image.Width, |
|
|
|
|
Height = image.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
|
StrokeColor = new MagickColor(strokeColor ?? MagickColors.Black), |
|
|
|
@ -160,15 +187,15 @@ public static partial class ImageManager |
|
|
|
|
return image; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, int x, int y, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null) |
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, int x, int y, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact", int strokeWidth = 2, MagickColor? strokeColor = null, bool wrapText = true, Gravity textGravity = Gravity.Northwest) |
|
|
|
|
{ |
|
|
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings() |
|
|
|
|
using var label = new MagickImage($"{(wrapText ? "caption" : "label")}:{text}", new MagickReadSettings() |
|
|
|
|
{ |
|
|
|
|
Width = image.Width, |
|
|
|
|
Height = image.Height, |
|
|
|
|
BackgroundColor = MagickColors.Transparent, |
|
|
|
|
FillColor = fontColor, |
|
|
|
|
TextGravity = Gravity.Center, |
|
|
|
|
TextGravity = textGravity, |
|
|
|
|
FontPointsize = fontSize, |
|
|
|
|
Font = font, |
|
|
|
|
TextEncoding = encoding, |
|
|
|
|