mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 15:59:42 -06:00
FF-1257 - added extra exif to read the date an image was taken
This commit is contained in:
@@ -53,10 +53,38 @@ public abstract class ImageBaseNode:Node
|
||||
else
|
||||
{
|
||||
using var image = Image.Load(args.WorkingFile, out IImageFormat format);
|
||||
UpdateImageInfo(args, image.Width, image.Height, format.Name, variables);
|
||||
DateTime? dateTaken = null;
|
||||
if (image.Metadata.ExifProfile != null)
|
||||
{
|
||||
args.Logger?.ILog("EXIF Profile found");
|
||||
var dateTimeOriginalString = image.Metadata.ExifProfile.GetValue(SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifTag.DateTimeOriginal)?.Value;
|
||||
if (string.IsNullOrWhiteSpace(dateTimeOriginalString))
|
||||
{
|
||||
args.Logger?.ILog("No DateTimeOriginal found");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dateTimeOriginalString) == false &&
|
||||
DateTime.TryParse(dateTimeOriginalString, out DateTime dateTimeOriginal))
|
||||
{
|
||||
dateTaken = dateTimeOriginal;
|
||||
args.Logger?.ILog("DateTimeOriginal: " + dateTimeOriginal);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Logger?.ILog("Invalid date format for DateTimeOriginal: " + dateTimeOriginalString);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Logger?.ILog("No EXIF Profile found");
|
||||
}
|
||||
|
||||
UpdateImageInfo(args, image.Width, image.Height, format.Name, variables: variables, dateTaken: dateTaken);
|
||||
}
|
||||
}
|
||||
protected void UpdateImageInfo(NodeParameters args, int width, int height, string format, Dictionary<string, object> variables = null)
|
||||
protected void UpdateImageInfo(NodeParameters args, int width, int height, string format, Dictionary<string, object> variables = null, DateTime? dateTaken = null)
|
||||
{
|
||||
var imageInfo = new ImageInfo
|
||||
{
|
||||
@@ -74,6 +102,14 @@ public abstract class ImageBaseNode:Node
|
||||
variables.AddOrUpdate("img.IsPortrait", imageInfo.IsPortrait);
|
||||
variables.AddOrUpdate("img.IsLandscape", imageInfo.IsLandscape);
|
||||
|
||||
if (dateTaken != null)
|
||||
{
|
||||
variables.AddOrUpdate("img.DateTaken.Year", dateTaken.Value.Year);
|
||||
variables.AddOrUpdate("img.DateTaken.Month", dateTaken.Value.Month);
|
||||
variables.AddOrUpdate("img.DateTaken.Day", dateTaken.Value.Day);
|
||||
variables.AddOrUpdate("img.DateTaken.FulLDate", dateTaken.Value.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
var metadata = new Dictionary<string, object>();
|
||||
metadata.Add("Format", imageInfo.Format);
|
||||
metadata.Add("Width", imageInfo.Width);
|
||||
|
||||
@@ -20,7 +20,12 @@ public class ImageFile : ImageBaseNode
|
||||
{ "img.Height", 1080 },
|
||||
{ "img.Format", "PNG" },
|
||||
{ "img.IsPortrait", true },
|
||||
{ "img.IsLandscape", false }
|
||||
{ "img.IsLandscape", false },
|
||||
|
||||
{ "img.DateTaken.Year", 2020 },
|
||||
{ "img.DateTaken.Month", 4 },
|
||||
{ "img.DateTaken.Day", 20 },
|
||||
{ "img.DateTaken.FulLDate", "2020-04-20" }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using ImageMagick;
|
||||
using SixLabors.ImageSharp.Formats;
|
||||
|
||||
Reference in New Issue
Block a user