using FileFlows.Plugin.Helpers; using FileFlows.Plugin.Types; namespace FileFlows.ImageNodes.Images; /// /// Flow element that resizes an image /// public class ImageResizer: ImageNode { /// public override int Inputs => 1; /// public override int Outputs => 1; /// public override FlowElementType Type => FlowElementType.Process; /// public override string Icon => "fas fa-expand"; /// public override string HelpUrl => "https://fileflows.com/docs/plugins/image-nodes/image-resizer"; /// /// Gets or sets the resize mode /// [Select(nameof(ResizeModes), 3)] public ResizeMode Mode { get; set; } private static List? _ResizeModes; /// /// Gets the resize modes /// public static List ResizeModes { get { if (_ResizeModes == null) { _ResizeModes = new List { new () { Value = ResizeMode.Fill, Label = "Fill"}, new () { Value = ResizeMode.Contain, Label = "Contain"}, new () { Value = ResizeMode.Cover, Label = "Cover"}, new () { Value = ResizeMode.Min, Label = "Min"}, new () { Value = ResizeMode.Max, Label = "Max"}, new () { Value = ResizeMode.Pad, Label = "Pad"} }; } return _ResizeModes; } } /// /// Gets or sets the new width /// [NumberPercent(5, "Labels.Pixels", 0, false)] public NumberPercent? Width { get; set; } /// /// Gets or sets the new height /// [NumberPercent(6, "Labels.Pixels", 0, false)] public NumberPercent? Height { get; set; } /// protected override Result PerformAction(NodeParameters args, string localFile, string destination) { float w = Width!.Percentage ? (int)(CurrentWidth * (Width.Value / 100f)) : Width.Value; float h = Height!.Percentage ? (int)(CurrentHeight * (Height.Value / 100f)) : Height.Value; return args.ImageHelper.Resize(localFile, destination, (int)w, (int)h, Mode, GetImageTypeFromFormat(), Quality); } }