oliverbooth.dev/OliverBooth/Data/Web/Book.cs
Oliver Booth 6ec4103a3a
refactor: separate Markdig extensions from project
Also introduces .Common project to house common references and types
2024-05-05 02:18:20 +01:00

37 lines
935 B
C#

using NetBarcode;
using OliverBooth.Common.Data.Web;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Processing;
namespace OliverBooth.Data.Web;
/// <summary>
/// Represents a book.
/// </summary>
internal sealed class Book : IBook
{
/// <inheritdoc />
public string Author { get; }
/// <inheritdoc />
public string Isbn { get; }
/// <inheritdoc />
public BookState State { get; }
/// <inheritdoc />
public string Title { get; }
public string GetBarcode()
{
var barcode = new Barcode(Isbn, NetBarcode.Type.EAN13);
using var image = barcode.GetImage();
int width = image.Width;
int height = image.Height;
image.Mutate(i => i.Pad(width + 10, height + 10, Color.White));
image.Mutate(i => i.Resize(i.GetCurrentSize() / 4 * 3));
return image.ToBase64String(PngFormat.Instance);
}
}