45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
|
|
using System.IO;
|
||
|
|
using SixLabors.ImageSharp;
|
||
|
|
using SixLabors.ImageSharp.PixelFormats;
|
||
|
|
using SixLabors.ImageSharp.Processing;
|
||
|
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
||
|
|
|
||
|
|
namespace MaddoShared.ImageSharpTests.Helpers
|
||
|
|
{
|
||
|
|
public static class TestImageFactory
|
||
|
|
{
|
||
|
|
public static string CreateSolidJpeg(string directory, string fileName, int width, int height, Rgba32 color)
|
||
|
|
{
|
||
|
|
Directory.CreateDirectory(directory);
|
||
|
|
var path = Path.Combine(directory, fileName);
|
||
|
|
using var img = new Image<Rgba32>(width, height, color);
|
||
|
|
var encoder = new JpegEncoder { Quality = 90 };
|
||
|
|
img.Save(path, encoder);
|
||
|
|
return path;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static string CreateSolidPng(string directory, string fileName, int width, int height, Rgba32 color)
|
||
|
|
{
|
||
|
|
Directory.CreateDirectory(directory);
|
||
|
|
var path = Path.Combine(directory, fileName);
|
||
|
|
using var img = new Image<Rgba32>(width, height, color);
|
||
|
|
img.SaveAsPng(path);
|
||
|
|
return path;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static string CreateJpegWithExifOrientation(string directory, string fileName, int width, int height, Rgba32 color, ushort orientation)
|
||
|
|
{
|
||
|
|
Directory.CreateDirectory(directory);
|
||
|
|
var path = Path.Combine(directory, fileName);
|
||
|
|
using var img = new Image<Rgba32>(width, height, color);
|
||
|
|
// Add EXIF orientation
|
||
|
|
var profile = new ExifProfile();
|
||
|
|
profile.SetValue(ExifTag.Orientation, orientation);
|
||
|
|
img.Metadata.ExifProfile = profile;
|
||
|
|
var encoder = new JpegEncoder { Quality = 90 };
|
||
|
|
img.Save(path, encoder);
|
||
|
|
return path;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|