- Added ImageCreatorImageSharp class for image creation, handling EXIF orientation, resizing, and saving images. - Replaced GDI+ dependencies with ImageSharp for cross-platform compatibility. - Introduced methods for drawing text and logos on images, including handling transparency and positioning. - Created a test plan for validating ImageCreatorImageSharp functionality, focusing on image resizing, text positioning, logo features, and EXIF orientation. - Added documentation for the test plan outlining goals, project structure, and implementation notes.
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;
|
|
}
|
|
}
|
|
}
|