👔 Optimize the file service handling for image
This commit is contained in:
parent
d91b705b9a
commit
d9747daab9
@ -52,7 +52,9 @@ public class FileService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static readonly string TempFilePrefix = "dyn-cloudfile";
|
private static readonly string TempFilePrefix = "dyn-cloudfile";
|
||||||
private static readonly string[] AnimatedImageTypes = new[] { "image/gif", "image/apng", "image/webp", "image/avif" };
|
|
||||||
|
private static readonly string[] AnimatedImageTypes =
|
||||||
|
new[] { "image/gif", "image/apng", "image/webp", "image/avif" };
|
||||||
|
|
||||||
// The analysis file method no longer will remove the GPS EXIF data
|
// The analysis file method no longer will remove the GPS EXIF data
|
||||||
// It should be handled on the client side, and for some specific cases it should be keep
|
// It should be handled on the client side, and for some specific cases it should be keep
|
||||||
@ -118,11 +120,11 @@ public class FileService(
|
|||||||
foreach (var field in vipsImage.GetFields())
|
foreach (var field in vipsImage.GetFields())
|
||||||
{
|
{
|
||||||
var value = vipsImage.Get(field);
|
var value = vipsImage.Get(field);
|
||||||
|
|
||||||
// Skip GPS-related EXIF fields to remove location data
|
// Skip GPS-related EXIF fields to remove location data
|
||||||
if (IsGpsExifField(field))
|
if (IsGpsExifField(field))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
exif.Add(field, value);
|
exif.Add(field, value);
|
||||||
if (field == "orientation") orientation = (int)value;
|
if (field == "orientation") orientation = (int)value;
|
||||||
}
|
}
|
||||||
@ -190,7 +192,8 @@ public class FileService(
|
|||||||
{
|
{
|
||||||
logger.LogInformation(
|
logger.LogInformation(
|
||||||
"File {fileId} is an animated image (MIME: {mime}), skipping WebP conversion.", fileId,
|
"File {fileId} is an animated image (MIME: {mime}), skipping WebP conversion.", fileId,
|
||||||
contentType);
|
contentType
|
||||||
|
);
|
||||||
var tempFilePath = Path.Join(Path.GetTempPath(), $"{TempFilePrefix}#{file.Id}");
|
var tempFilePath = Path.Join(Path.GetTempPath(), $"{TempFilePrefix}#{file.Id}");
|
||||||
result.Add((tempFilePath, string.Empty));
|
result.Add((tempFilePath, string.Empty));
|
||||||
return;
|
return;
|
||||||
@ -200,9 +203,8 @@ public class FileService(
|
|||||||
|
|
||||||
using var vipsImage = Image.NewFromFile(ogFilePath);
|
using var vipsImage = Image.NewFromFile(ogFilePath);
|
||||||
var imagePath = Path.Join(Path.GetTempPath(), $"{TempFilePrefix}#{file.Id}");
|
var imagePath = Path.Join(Path.GetTempPath(), $"{TempFilePrefix}#{file.Id}");
|
||||||
vipsImage.Autorot();
|
vipsImage.Autorot().WriteToFile(imagePath + ".webp",
|
||||||
vipsImage.WriteToFile(imagePath + ".webp",
|
new VOption { { "lossless", true }, { "strip", true } });
|
||||||
new VOption { { "lossless", true } });
|
|
||||||
result.Add((imagePath + ".webp", string.Empty));
|
result.Add((imagePath + ".webp", string.Empty));
|
||||||
|
|
||||||
if (vipsImage.Width * vipsImage.Height >= 1024 * 1024)
|
if (vipsImage.Width * vipsImage.Height >= 1024 * 1024)
|
||||||
@ -213,8 +215,8 @@ public class FileService(
|
|||||||
|
|
||||||
// Create and save image within the same synchronous block to avoid disposal issues
|
// Create and save image within the same synchronous block to avoid disposal issues
|
||||||
using var compressedImage = vipsImage.Resize(scale);
|
using var compressedImage = vipsImage.Resize(scale);
|
||||||
compressedImage.WriteToFile(imageCompressedPath + ".webp",
|
compressedImage.Autorot().WriteToFile(imageCompressedPath + ".webp",
|
||||||
new VOption { { "Q", 80 } });
|
new VOption { { "Q", 80 }, { "strip", true } });
|
||||||
|
|
||||||
result.Add((imageCompressedPath + ".webp", ".compressed"));
|
result.Add((imageCompressedPath + ".webp", ".compressed"));
|
||||||
file.HasCompression = true;
|
file.HasCompression = true;
|
||||||
@ -514,7 +516,7 @@ public class FileService(
|
|||||||
var gpsFields = new[]
|
var gpsFields = new[]
|
||||||
{
|
{
|
||||||
"gps-latitude",
|
"gps-latitude",
|
||||||
"gps-longitude",
|
"gps-longitude",
|
||||||
"gps-altitude",
|
"gps-altitude",
|
||||||
"gps-latitude-ref",
|
"gps-latitude-ref",
|
||||||
"gps-longitude-ref",
|
"gps-longitude-ref",
|
||||||
@ -535,7 +537,7 @@ public class FileService(
|
|||||||
"gps-area-information"
|
"gps-area-information"
|
||||||
};
|
};
|
||||||
|
|
||||||
return gpsFields.Any(gpsField =>
|
return gpsFields.Any(gpsField =>
|
||||||
fieldName.Equals(gpsField, StringComparison.OrdinalIgnoreCase) ||
|
fieldName.Equals(gpsField, StringComparison.OrdinalIgnoreCase) ||
|
||||||
fieldName.StartsWith("gps", StringComparison.OrdinalIgnoreCase));
|
fieldName.StartsWith("gps", StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@
|
|||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FEmails_002FEmail_002ELandingResource/@EntryIndexRemoved">True</s:Boolean>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FEmails_002FEmail_002ELandingResource/@EntryIndexRemoved">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FEmail_002ELandingResource/@EntryIndexRemoved">True</s:Boolean>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FEmail_002ELandingResource/@EntryIndexRemoved">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FEmailResource/@EntryIndexedValue">False</s:Boolean>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FEmailResource/@EntryIndexedValue">False</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FNotificationResource/@EntryIndexedValue">False</s:Boolean>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002ESphere_002FResources_002FLocalization_002FNotificationResource/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -133,4 +133,4 @@
|
|||||||
<s:String x:Key="/Default/ResxEditorPersonal/DisabledLanguages/@EntryValue"></s:String>
|
<s:String x:Key="/Default/ResxEditorPersonal/DisabledLanguages/@EntryValue"></s:String>
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/ShowComments/@EntryValue">False</s:Boolean>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/ShowComments/@EntryValue">False</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/ShowOnlyErrors/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/ResxEditorPersonal/ShowOnlyErrors/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user