namespace FileFlows.ImageNodes.Images; using FileFlows.Plugin; /// /// Tests if a file is an image /// public class IsImage : Node { /// public override int Inputs => 1; /// public override int Outputs => 2; /// public override FlowElementType Type => FlowElementType.Logic; /// public override string HelpUrl => "https://fileflows.com/docs/plugins/image-nodes/is-image"; /// public override string Icon => "fas fa-question"; /// /// Gets or sets the file to test /// [TextVariable(1)] public string File { get; set; } = null!; /// public override int Execute(NodeParameters args) { var file = args.ReplaceVariables(File ?? string.Empty)?.EmptyAsNull() ?? args.WorkingFile; args.Logger?.ILog("Testing file: " + file); var localFile = args.FileService.GetLocalPath(file); if (localFile.IsFailed) { args.FailureReason = "Working file cannot be read: " + localFile.Error; args.Logger?.ELog(args.FailureReason); return -1; } var info = args.ImageHelper.GetInfo(localFile); if(info.Failed(out string error)) { args.Logger?.ILog("Not an image"); args.Logger?.ILog(error); return 2; } args.Logger?.ILog("Is an image"); args.Logger?.ILog("Width: " + info.Value.Width); args.Logger?.ILog("Height: " + info.Value.Height); if(string.IsNullOrEmpty(info.Value.Format) == false) args.Logger?.ILog("Format: " + info.Value.Format); return 1; } }