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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Fit #349's images back face, compress into ZIPs, count saved pictures
KnifeLemonc1315c86083e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d5a1cee0..d35943e7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -144,8 +144,8 @@ pt-BR: Correções de segurança para e-books, SVG, modelos 3D e e-mails, e muitrun. Attachments dragged out of Outlook and files dragged out of a ZIP in Explorer open the donut too.- **The donut's back face** (issue #195). Every donut has a second set of up to 12 slices. While the donut is open,press **Tab** or turn the **mouse wheel** to flip it; the hub shows the hint when the back has something for your- files. Built-in donuts come with a back face: Crop, Rotate, Flip, Remove background and Live Photo video on the image- donut, Compress PDF on the PDF donut, frame extraction and Live / Motion Photos on the video donut, One ZIP on most.+ files. Built-in donuts come with a back face: Crop, Rotate, Flip and Remove background on the image donut,+ Compress PDF on the PDF donut, frame extraction and Live / Motion Photos on the video donut, One ZIP on most.The Front / Back switch in Settings → Donut toolbar edits it, and Settings → Shortcuts → "Flip the donut" changes thekey or turns the wheel off.- **Crop** (by @smjrifle). The Crop slice (on the back of the image donut) opens your pictures one after another in adiff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex b35dd57d..e80f3c9e 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -703,11 +703,13 @@ PDFsharp and Magick.NET; nothing has to be installed.## Media tools-The everyday presets on the back faces of the images, PDF, video and audio donuts. Video and audio need FFmpeg.+Everyday presets, on the back faces of the images, PDF, video and audio donuts where they fit ("Video from images" is+in the preset library only). Video and audio need FFmpeg.- **Compress image / video / audio** re-encode smaller (quality 75, never above a JPEG's own and PNG at zlib level 9;H.264 at the Small quality, at most 1080p; AAC at the Small quality). A copy in the same format that isn't smaller is- replaced by the source, with the same notice as Compress PDF (`OutputRule.OnlyIfSmaller`).+ replaced by the source, with the same notice as Compress PDF (`OutputRule.OnlyIfSmaller`); under "Save as ZIP" the+ source goes into the ZIP instead.- **Extract audio** copies AAC or ALAC into M4A without an encode (`MediaOptions.CopyAudioWhenPossible`); other soundis encoded to AAC.- **Merge videos** copies the clips with the concat demuxer only when all share the codec setup (ffprobe's extradata@@ -715,12 +717,14 @@ The everyday presets on the back faces of the images, PDF, video and audio donutframe and encoded, a clip without sound silent for its length. **Merge audio** always decodes and joins the soundinto one M4A, so no encoder padding or gap is left between files. Both are in `Media/MediaJoining.cs`.- **Video from images**: each picture is fitted into 1920 × 1080 as a JPEG, then shown for the preset's seconds with- 1 s crossfades (`xfade`) or cuts. At most `MediaOptions.MaxSlides` (300) pictures; the queue refuses more before any- is converted. A filter graph too long for a command line goes into a `-/filter_complex` file.+ crossfades (`xfade`) of 1 s, at most half a picture's time, or cuts. At most `MediaOptions.MaxSlides` (300)+ pictures, not counting downloads that failed; the queue refuses more before any is converted. A filter graph too+ long for a command line goes into a `-/filter_complex` file.- **Remove metadata** keeps the format. Images lose EXIF, XMP, IPTC, comments and the ICC profile, and a JPEG keepsits own quality. Video and audio are copied without global and per-stream tags, chapters and data tracks; an MKV'sattachments (subtitle fonts) stay, with their file name and type. PDFs lose their document information and every- XMP packet (`PdfSharpConverter.StripMetadata`); pages, links, bookmarks and form fields stay.+ XMP packet (`PdfSharpConverter.StripMetadata`), and PDFsharp writes a new one holding only its own name and the save+ date; pages, links, bookmarks and form fields stay.## Office Open XML variantsdiff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.csindex 05a22fd2..a9ccbd8a 100644--- a/src/Filee.Core/Conversion/JobQueue.cs+++ b/src/Filee.Core/Conversion/JobQueue.cs@@ -352,11 +352,13 @@ public sealed class JobQueue : IAsyncDisposable{var slideshow = job.Preset.Media.Slideshow;var target = FormatRegistry.Get(job.Preset.TargetFormat);- // Before any picture is converted: too many fail at once instead of after minutes of PNG steps.- if (slideshow && job.Files.Count(f => !Stopped(f)) > MediaOptions.MaxSlides)+ // Before any picture is converted: too many fail at once instead of after minutes of PNG steps. Files whose+ // download already failed don't count.+ var pictures = job.Files.Count(f => !Stopped(f));+ if (slideshow && pictures > MediaOptions.MaxSlides){foreach (var f in job.Files.Where(f => !Stopped(f)))- FailFile(job, f, "error.too_many_pictures", $"{job.Files.Count} > {MediaOptions.MaxSlides}");+ FailFile(job, f, "error.too_many_pictures", $"{pictures} > {MediaOptions.MaxSlides}");return;}var parts = new IReadOnlyList<string>?[job.Files.Count];@@ -754,7 +756,8 @@ public sealed class JobQueue : IAsyncDisposableinputs = outputs;}- if (!zipResult && finalOutput && job.Preset.Output.OnlyIfSmaller && inputs.Count == 1 && CopyIfNotSmaller(file.SourcePath, inputs[0]))+ // Under "Save as ZIP" the output is still in the work folder: the source copied over it goes into the ZIP.+ if (finalOutput && job.Preset.Output.OnlyIfSmaller && inputs.Count == 1 && CopyIfNotSmaller(file.SourcePath, inputs[0]))file.NoticeKey = "notice.pdf_not_smaller";if (zipResult && inputs.Count > 0)diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.csindex 539d8d56..6c58997d 100644--- a/src/Filee.Core/Presets/BuiltInData.cs+++ b/src/Filee.Core/Presets/BuiltInData.cs@@ -435,8 +435,9 @@ public static class BuiltInDataId = "images", NameKey = "profile.images",Extensions = ExtensionsOf(FormatCategory.Image),PresetIds = ["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],- BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "trim-transparent", "grayscale", "extract-motion", "to-avif", "to-gif",- "merge-pdf", "compress-image", "remove-metadata", "zip-all"],+ // Full (ToolbarProfile.MaxSlices): "Extract Live Photo video" stays in the library, on no donut.+ BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "trim-transparent", "grayscale", "to-avif", "to-gif", "merge-pdf",+ "compress-image", "remove-metadata", "zip-all"],},new(){diff --git a/tests/Filee.Core.Tests/MediaToolTests.cs b/tests/Filee.Core.Tests/MediaToolTests.csindex 6bcbab38..b8ba6db9 100644--- a/tests/Filee.Core.Tests/MediaToolTests.cs+++ b/tests/Filee.Core.Tests/MediaToolTests.cs@@ -98,10 +98,43 @@ public class MediaToolTestsvar video = profiles.Single(p => p.Id == "video").BackPresetIds!;Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "video").BackPresetIds, video);Assert.Equal(full, pdf.BackPresetIds);+ Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "images").BackPresetIds,+ profiles.Single(p => p.Id == "images").BackPresetIds);Assert.False(SettingsMigrations.ApplyToLibrary(36, presets, profiles)); // once onlyAssert.False(SettingsMigrations.ApplyToLibrary(AppSettings.CurrentSchemaVersion, presets, profiles));}+ [Fact]+ public void A_new_library_images_back_face_is_full_without_the_live_photo_video()+ {+ var presets = BuiltInData.CreatePresets();+ var images = BuiltInData.CreateProfiles().Single(p => p.Id == "images").BackPresetIds!;+ Assert.Equal(ToolbarProfile.MaxSlices, images.Count);+ Assert.Contains("compress-image", images);+ Assert.Contains("remove-metadata", images);+ Assert.DoesNotContain("extract-motion", images);+ Assert.Single(presets, p => p.Id == "extract-motion"); // still in the library+ }++ [Fact]+ public void A_schema_36_images_back_face_takes_what_fits_and_never_more_than_the_donut_holds()+ {+ var presets = BuiltInData.CreatePresets().Where(p => !ToolIds.Contains(p.Id)).ToList();+ var profiles = BuiltInData.CreateProfiles();+ // The images back face as schema 36 wrote it: eleven slices, "Extract Live Photo video" among them.+ var images = profiles.Single(p => p.Id == "images");+ images.BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "trim-transparent", "grayscale", "extract-motion",+ "to-avif", "to-gif", "merge-pdf", "zip-all"];++ Assert.True(SettingsMigrations.ApplyToLibrary(36, presets, profiles));++ Assert.Equal(ToolbarProfile.MaxSlices, images.BackPresetIds.Count);+ Assert.Equal(["merge-pdf", "compress-image", "zip-all"], images.BackPresetIds[^3..]);+ Assert.DoesNotContain("remove-metadata", images.BackPresetIds); // no room left, still in the library+ Assert.Single(presets, p => p.Id == "remove-metadata");+ Assert.All(profiles, p => Assert.InRange(p.BackPresetIds!.Count, 0, ToolbarProfile.MaxSlices));+ }+[Fact]public void Extract_audio_comes_onto_a_video_back_face_without_the_m4a_slice_when_there_is_room(){@@ -220,6 +253,33 @@ public class MediaToolTestsAssert.Equal("x", File.ReadAllText(Path.Combine(dir.Path, "tiny_compressed.jpg"))); // the original, copied}+ [Fact]+ public async Task Compressing_into_a_zip_keeps_the_original_when_the_copy_would_not_be_smaller()+ {+ using var dir = new TempDir();+ var big = dir.File("big.jpg", new string('x', 10_000));+ var tiny = dir.File("tiny.jpg", "x");+ var preset = BuiltIn("compress-image").Clone();+ preset.Output.ZipResult = true;+ await using var queue = new JobQueue(new ConverterCatalog([new FakeConverter("magick", new ConversionEdge("jpg", "jpg"))]));++ var job = await Run(queue, [big, tiny], preset);++ Assert.Equal(JobState.Completed, job.State);+ Assert.Null(job.Files[0].NoticeKey);+ Assert.True(ZipEntry(job.Files[0].Outputs.Single()).Length < 10_000);+ Assert.Equal("notice.pdf_not_smaller", job.Files[1].NoticeKey);+ Assert.Equal("x", ZipEntry(job.Files[1].Outputs.Single())); // the original, packed+ Assert.Equal("x", File.ReadAllText(tiny));++ static string ZipEntry(string zip)+ {+ using var archive = System.IO.Compression.ZipFile.OpenRead(zip);+ using var reader = new StreamReader(Assert.Single(archive.Entries).Open());+ return reader.ReadToEnd();+ }+ }+[Fact]public async Task A_failed_join_frees_its_name_and_removes_the_subfolder_it_made(){@@ -270,9 +330,38 @@ public class MediaToolTestsAssert.Equal(JobState.Failed, job.State);Assert.All(job.Files, f => Assert.Equal("error.too_many_pictures", f.ErrorKey));+ Assert.All(job.Files, f => Assert.Equal($"{MediaOptions.MaxSlides + 1} > {MediaOptions.MaxSlides}", f.ErrorDetail));Assert.Empty(joiner.Inputs);}+ [Fact]+ public async Task Too_many_pictures_counts_only_the_ones_that_were_saved()+ {+ using var dir = new TempDir();+ var photos = Enumerable.Range(1, MediaOptions.MaxSlides + 1).Select(i => dir.File($"p{i:D3}.jpg")).ToList();+ var converter = new FakeConverter("magick", new ConversionEdge("jpg", "png")) { Throw = true };+ await using var queue = new JobQueue(new ConverterCatalog([converter]), mediaJoiner: new FakeJoiner());+ var job = new ConversionJob([.. photos, "web/lost.jpg"], BuiltIn("video-from-images"), "Test", new FailingFetcher());++ await queue.RunAsync(job);++ Assert.Equal("error.web_download_failed", job.Files[^1].ErrorKey);+ Assert.All(job.Files.SkipLast(1), f => Assert.Equal($"{MediaOptions.MaxSlides + 1} > {MediaOptions.MaxSlides}", f.ErrorDetail));+ }++ /// <summary>A browser download that never arrives.</summary>+ private sealed class FailingFetcher : ISourceFetcher+ {+ public bool Fetches(string source) => source.StartsWith("web/", StringComparison.Ordinal);++ public Task<string> FetchAsync(string source, IProgress<TransferProgress> progress, CancellationToken cancellationToken) =>+ throw new IOException("gone");++ public void Release(ConversionJob job)+ {+ }+ }+[Fact]public async Task A_kept_original_goes_next_to_its_source_like_a_compressed_copy(){