Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Recognize PNG and JPEG download extension aliases

Nitjsefnie5554e7057b45
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5a1cee0..2b1eae49 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -242,6 +242,8 @@ pt-BR: Correções de segurança para e-books, SVG, modelos 3D e e-mails, e muit
### Fixed
+- PNG and JPEG pictures named `.png_large` or `.jpg_large` are recognised for conversion and by the images donut,
+ including existing libraries. Custom extension assignments stay as they are.
- A failed or cancelled conversion left a half-written file where the result should be, and converting again gave
`photo (2).png` (by @flexeykinDev). A file the preset was going to overwrite is never deleted.
- Work folders a crash or a shutdown left in the temp folder stayed there for good. They are deleted after a day (by
diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.cs
index ba30df55..d6017540 100644
--- a/src/Filee.Core/Formats/FormatRegistry.cs
+++ b/src/Filee.Core/Formats/FormatRegistry.cs
@@ -13,8 +13,8 @@ public static class FormatRegistry
public static IReadOnlyList<FileFormat> Known { get; } =
[
// Raster images
- new("png", "PNG", FormatCategory.Image, ["png"]),
- new("jpg", "JPG", FormatCategory.Image, ["jpg", "jpeg", "jpe", "jfif"]),
+ new("png", "PNG", FormatCategory.Image, ["png", "png_large"]),
+ new("jpg", "JPG", FormatCategory.Image, ["jpg", "jpeg", "jpe", "jfif", "jpg_large"]),
new("webp", "WEBP", FormatCategory.Image, ["webp"]),
new("tiff", "TIFF", FormatCategory.Image, ["tiff", "tif"]),
new("bmp", "BMP", FormatCategory.Image, ["bmp", "dib"]),
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index 1e4cbe88..c9856e03 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -112,7 +112,7 @@ public sealed class DonutSettings
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
- public const int CurrentSchemaVersion = 38;
+ public const int CurrentSchemaVersion = 39;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 885ddb08..6f2b9380 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -794,6 +794,9 @@ internal static class SettingsMigrations
// v38: Tajima embroidery designs (.dst) learn the vector donut; custom claims stay put.
if (from < 38)
changed |= LearnExtensions(profiles, out _, ["dst"]);
+ // v39: PNG/JPEG download aliases learn the images donut; custom claims stay put.
+ if (from < 39)
+ changed |= LearnExtensions(profiles, out _, ["png_large", "jpg_large"]);
return changed;
}
diff --git a/tests/Filee.Core.Tests/ImageExtensionAliasTests.cs b/tests/Filee.Core.Tests/ImageExtensionAliasTests.cs
new file mode 100644
index 00000000..1b5d3538
--- /dev/null
+++ b/tests/Filee.Core.Tests/ImageExtensionAliasTests.cs
@@ -0,0 +1,78 @@
+// PNG/JPEG download aliases are recognised and learnt by image profiles without taking custom claims.
+
+using Filee.Core.Formats;
+using Filee.Core.Presets;
+using Filee.Core.Profiles;
+using Filee.Core.Settings;
+
+namespace Filee.Core.Tests;
+
+public class ImageExtensionAliasTests
+{
+ [Theory]
+ [InlineData("photo.png_large", "png")]
+ [InlineData("photo.jpg_large", "jpg")]
+ [InlineData("photo.PnG_LaRgE", "png")]
+ [InlineData("photo.JpG_LaRgE", "jpg")]
+ public void Large_image_extensions_resolve_to_the_existing_format(string file, string format) =>
+ Assert.Same(FormatRegistry.Get(format), FormatRegistry.Detect(file));
+
+ [Fact]
+ public void An_unknown_large_extension_is_not_detected() =>
+ Assert.Null(FormatRegistry.Detect("file.unknown_large"));
+
+ [Fact]
+ public void Fresh_image_profiles_take_both_aliases()
+ {
+ var profiles = BuiltInData.CreateProfiles();
+
+ Assert.Equal("images", ProfileSelector.Select(profiles, ["photo.png_large", "photo.JpG_LaRgE"])?.Id);
+ }
+
+ [Fact]
+ public void Version_38_libraries_learn_both_aliases_once()
+ {
+ var presets = BuiltInData.CreatePresets();
+ var profiles = BuiltInData.CreateProfiles();
+ var images = profiles.Single(p => p.Id == "images");
+ images.Extensions.RemoveAll(e => e is "png_large" or "jpg_large" or "png");
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(38, presets, profiles));
+
+ Assert.Contains("png_large", images.Extensions);
+ Assert.Contains("jpg_large", images.Extensions);
+ Assert.DoesNotContain("png", images.Extensions);
+ Assert.False(SettingsMigrations.ApplyToLibrary(38, presets, profiles));
+ }
+
+ [Theory]
+ [InlineData("PNG_LARGE", "jpg_large")]
+ [InlineData("JPG_LARGE", "png_large")]
+ public void Version_38_libraries_preserve_custom_alias_claims(string claimed, string learned)
+ {
+ using var dir = new TempDir();
+ var store = new UserDataStore(dir.Path);
+ store.Load();
+ store.Settings.SchemaVersion = 38;
+ foreach (var profile in store.Profiles)
+ profile.Extensions.RemoveAll(e => e is "png_large" or "jpg_large");
+ store.Profiles.Add(new ToolbarProfile { Id = "my-photos", Extensions = [claimed] });
+ store.SaveLibrary();
+ store.SaveSettings();
+
+ var upgraded = new UserDataStore(dir.Path);
+ upgraded.Load();
+
+ var images = upgraded.Profiles.Single(p => p.Id == "images");
+ Assert.Contains(learned, images.Extensions);
+ Assert.False(images.Matches(claimed));
+ Assert.Equal("my-photos", ProfileSelector.Select(upgraded.Profiles, ["photo." + claimed])?.Id);
+ Assert.Equal(AppSettings.CurrentSchemaVersion, upgraded.Settings.SchemaVersion);
+
+ var reloaded = new UserDataStore(dir.Path);
+ reloaded.Load();
+ Assert.Contains(learned, reloaded.Profiles.Single(p => p.Id == "images").Extensions);
+ Assert.Equal("my-photos", Assert.Single(reloaded.Profiles, p => p.Matches(claimed)).Id);
+ Assert.Equal(AppSettings.CurrentSchemaVersion, reloaded.Settings.SchemaVersion);
+ }
+}
diff --git a/tests/Filee.Engines.Tests/ImageAndPdfTests.cs b/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
index f1893c6b..e18d0ad1 100644
--- a/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
+++ b/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
@@ -14,6 +14,24 @@ public class ImageAndPdfTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.All(job.Outputs, o => Assert.True(new FileInfo(o).Length > 0, o));
}
+ [Theory]
+ [InlineData("photo.png_large", MagickFormat.Png)]
+ [InlineData("photo.jpg_large", MagickFormat.Jpeg)]
+ public async Task Large_image_aliases_convert_to_png(string name, MagickFormat format)
+ {
+ var dir = fx.NewFolder();
+ var source = EngineFixture.MakeImage(dir, name, format, 64, 48);
+
+ var job = await fx.ConvertAsync([source], new Preset { TargetFormat = "png" });
+
+ AssertDone(job);
+ var output = Assert.Single(job.Outputs);
+ Assert.Equal(".png", Path.GetExtension(output));
+ using var result = new MagickImage(output);
+ Assert.Equal(MagickFormat.Png, result.Format);
+ Assert.Equal((64u, 48u), (result.Width, result.Height));
+ }
+
[Theory]
[InlineData("jpg", MagickFormat.Jpeg)]
[InlineData("webp", MagickFormat.WebP)]