You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
using System.Text;
|
|
using ImageMagick;
|
|
using Kynareth.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Kynareth.Managers;
|
|
|
|
public static partial class ImageManager
|
|
{
|
|
public static void Configure(IConfiguration configuration, IWebHostEnvironment appEnvironment)
|
|
{
|
|
ConfigureGeneration(configuration, appEnvironment);
|
|
ConfigureManipulation(configuration, appEnvironment);
|
|
}
|
|
|
|
private static ObjectResult GetResult(int statusCode, object data)
|
|
=> new(data) { StatusCode = statusCode };
|
|
|
|
public static MagickImage WriteText(this MagickImage image, string text, PositionRect rect, MagickColor fontColor, Encoding encoding, double fontSize, string font = "Impact")
|
|
{
|
|
using var label = new MagickImage($"caption:{text}", new MagickReadSettings()
|
|
{
|
|
Width = rect.Width,
|
|
Height = rect.Height,
|
|
BackgroundColor = MagickColors.Transparent,
|
|
FillColor = fontColor,
|
|
TextGravity = Gravity.Center,
|
|
FontPointsize = fontSize,
|
|
Font = font,
|
|
TextEncoding = encoding,
|
|
StrokeColor = MagickColors.Black,
|
|
StrokeWidth = 2
|
|
});
|
|
|
|
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, string font = "Impact")
|
|
{
|
|
using var label = new MagickImage($"label:{text}", new MagickReadSettings()
|
|
{
|
|
Width = rect.Width,
|
|
Height = rect.Height,
|
|
BackgroundColor = MagickColors.Transparent,
|
|
FillColor = fontColor,
|
|
TextGravity = Gravity.Center,
|
|
Font = font,
|
|
TextEncoding = encoding,
|
|
StrokeColor = MagickColors.Black,
|
|
StrokeWidth = 2
|
|
});
|
|
|
|
image.Composite(label, rect.X, rect.Y, CompositeOperator.Over);
|
|
|
|
return image;
|
|
}
|
|
} |