FF-1040 - added min/max to image resizer

This commit is contained in:
John Andrews
2023-07-28 14:05:10 +12:00
parent adb5e78452
commit 8a5d3aec9d
3 changed files with 26 additions and 12 deletions

View File

@@ -5,5 +5,8 @@ public enum ResizeMode
Fill = 1,
Contain = 2,
Cover = 3,
None = 4
None = 4,
Min = 5,
Max = 6,
}

View File

@@ -33,10 +33,12 @@ public class ImageResizer: ImageNode
{
_ResizeModes = new List<ListOption>
{
new ListOption { Value = Images.ResizeMode.Fill, Label = "Fill (Stretches to fit)"},
new ListOption { Value = Images.ResizeMode.Contain, Label = "Contain (Preserves aspect ratio but contained in bounds)"},
new ListOption { Value = Images.ResizeMode.Cover, Label = "Cover (Preserves aspect ratio)"},
new ListOption { Value = Images.ResizeMode.None, Label = "None (Not resized)"}
new () { Value = ResizeMode.Fill, Label = "Fill (Stretches to fit)"},
new () { Value = ResizeMode.Contain, Label = "Contain (Preserves aspect ratio but contained in bounds)"},
new () { Value = ResizeMode.Cover, Label = "Cover (Preserves aspect ratio)"},
new () { Value = ResizeMode.Min, Label = "Min (Resizes the image until the shortest side reaches the set given dimension)"},
new () { Value = ResizeMode.Max, Label = "Max (Constrains the resized image to fit the bounds of its container maintaining the original aspect ratio)"},
new () { Value = ResizeMode.None, Label = "None (Not resized)"}
};
}
return _ResizeModes;
@@ -66,6 +68,10 @@ public class ImageResizer: ImageNode
break;
case ResizeMode.Fill: rzMode = SixLabors.ImageSharp.Processing.ResizeMode.Stretch;
break;
case ResizeMode.Min: rzMode = SixLabors.ImageSharp.Processing.ResizeMode.Min;
break;
case ResizeMode.Max: rzMode = SixLabors.ImageSharp.Processing.ResizeMode.Max;
break;
default: rzMode = SixLabors.ImageSharp.Processing.ResizeMode.BoxPad;
break;
}

View File

@@ -3,6 +3,7 @@
using FileFlows.ImageNodes.Images;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
namespace FileFlows.ImageNodes.Tests;
@@ -35,9 +36,9 @@ public class ImageNodesTests
TestCropImage2 = "/home/john/Pictures/cropme.jpg";
TestCropImage3 = "/home/john/Pictures/crop.heic";
TestImageHeic = "/home/john/Pictures/crop.heic";
TestImage1 = "/home/john/Pictures/fileflows.png";
TestImage1 = "/home/john/Pictures/circle.jpg";
TestImage2 = "/home/john/Pictures/36410427.png";
TempDir = "/home/john/src/temp/";
TempDir = "/home/john/temp/";
}
}
@@ -86,16 +87,20 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Resize()
{
var args = new NodeParameters(TestImage1, new TestLogger(), false, string.Empty)
var logger = new TestLogger();
var args = new NodeParameters(TestImage1, logger, false, string.Empty)
{
TempPath = TempDir
};
var node = new ImageResizer();
node.Width = 1000;
node.Height = 500;
node.Mode = ResizeMode.Fill;
Assert.AreEqual(1, node.Execute(args));
node.Width = 1920;
node.Height = 1080;
node.Format = string.Empty;
node.Mode = ResizeMode.Max;
var result = node.Execute(args);
var log = logger.ToString();
Assert.AreEqual(1, result);
}
[TestMethod]