fixed image and comics plugins

This commit is contained in:
John Andrews
2022-08-06 12:33:20 +12:00
parent 9415c45134
commit 6ff7678ac6
21 changed files with 79 additions and 39 deletions

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -5,8 +5,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -97,6 +97,13 @@ public class ComicConverter: Node
Directory.Delete(directory, true);
args.Logger?.ILog("Created comic: " + file);
args.Logger?.ILog("Deleted temporary extraction directory: " + directory);
var metadata = new Dictionary<string, object>();
metadata.Add("Format", format);
metadata.Add("Pages", GetPageCount(format, file));
args.SetMetadata(metadata);
return file;
}
}

View File

@@ -28,7 +28,9 @@ internal class GenericExtractor
internal static int GetImageCount(string workingFile)
{
var rgxImages = new Regex(@"\.(jpeg|jpg|jpe|png|bmp|tiff|webp|gif)$");
return ArchiveFactory.GetFileParts(workingFile).Where(x => rgxImages.IsMatch(x)).Count();
var rgxImages = new Regex(@"\.(jpeg|jpg|jpe|png|bmp|tiff|webp|gif)$", RegexOptions.IgnoreCase);
using var archive = ArchiveFactory.Open(workingFile);
var files = archive.Entries.Where(entry => !entry.IsDirectory).ToArray();
return files.Where(x => rgxImages.IsMatch(x.Key)).Count();
}
}

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -9,8 +9,8 @@
<PublishTrimmed>true</PublishTrimmed>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -21,7 +21,8 @@
},
"ImageFormat": {
"Outputs": {
"1": "Image converted, saved to new temporary file"
"1": "Image converted, saved to new temporary file",
"2": "Image already in target format"
},
"Description": "Converts an image to the specified format",
"Fields": {

View File

@@ -6,6 +6,24 @@ public abstract class ImageBaseNode:Node
{
private const string IMAGE_INFO = "ImageInfo";
protected IImageFormat CurrentFormat { get; private set; }
protected int CurrentWidth{ get; private set; }
protected int CurrentHeight { get; private set; }
public override bool PreExecute(NodeParameters args)
{
using var image = Image.Load(args.WorkingFile, out IImageFormat format);
CurrentHeight = image.Height;
CurrentWidth = image.Width;
CurrentFormat = format;
var metadata = new Dictionary<string, object>();
metadata.Add("Format", CurrentFormat.Name);
metadata.Add("Width", CurrentWidth);
metadata.Add("Height", CurrentHeight);
args.SetMetadata(metadata);
return true;
}
protected void UpdateImageInfo(NodeParameters args, Dictionary<string, object> variables = null)
{
using var image = Image.Load(args.WorkingFile, out IImageFormat format);
@@ -57,6 +75,13 @@ public abstract class ImageBaseNode:Node
variables.AddOrUpdate("img.IsPortrait", imageInfo.IsPortrait);
variables.AddOrUpdate("img.IsLandscape", imageInfo.IsLandscape);
var metadata = new Dictionary<string, object>();
metadata.Add("Format", imageInfo.Format);
metadata.Add("Width", imageInfo.Width);
metadata.Add("Height", imageInfo.Height);
args.SetMetadata(metadata);
args.UpdateVariables(variables);
}

View File

@@ -1,20 +1,25 @@
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Processing;
namespace FileFlows.ImageNodes.Images;
public class ImageFormat: ImageNode
{
public override int Inputs => 1;
public override int Outputs => 1;
public override int Outputs => 2;
public override FlowElementType Type => FlowElementType.Process;
public override string Icon => "fas fa-file-image";
public override int Execute(NodeParameters args)
{
using var image = Image.Load(args.WorkingFile, out IImageFormat format);
var formatOpts = GetFormat(args);
if(formatOpts.format?.Name == CurrentFormat.Name)
{
args.Logger?.ILog("File already in format: " + formatOpts.format.Name);
return 2;
}
using var image = Image.Load(args.WorkingFile, out IImageFormat format);
SaveImage(args, image, formatOpts.file, formatOpts.format ?? format);
return 1;
}

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.171</FileVersion>
<ProductVersion>1.0.0.171</ProductVersion>
<FileVersion>1.0.0.172</FileVersion>
<ProductVersion>1.0.0.172</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>