Skip to content

Fix #24: Add fit to file size conversion - #65

Merged
Menelion merged 3 commits into
masterfrom
fix-24
Aug 21, 2026
Merged

Fix #24: Add fit to file size conversion#65
Menelion merged 3 commits into
masterfrom
fix-24

Conversation

@Menelion

Copy link
Copy Markdown
Contributor

Closes #24.

Pick a maximum file size — "your avatar must be under 200 KB" — and SIC! finds a combination of format, dimensions, and quality that fits under it, then converts to the one you choose.

What it does

Convert > Fit to File Size (Ctrl+Alt+Shift+F5), acting on the selected image. A small dialog takes the budget in KB plus an optional maximum width; the search then runs on a background thread behind a cancellable progress dialog and returns a ranked list of viable results, each spelled out in full:

WEBP — 1280x853, quality 82% — 195.4 KB (recommended)
PNG — 800x533, full quality — 187.2 KB

Picking one converts it through the standard output-path and filename-conflict flow, exactly like any other conversion.

How the search works

Every enabled target format is tried two ways: keep quality, shrink, and — for lossy formats that had to give up pixels — keep every pixel, drop quality. Both searches extrapolate rather than bisect: encoded size tracks pixel count closely, so one cheap 384 px probe yields a bytes-per-pixel estimate that aims every probe after it. The quality search picks a quality on a 768 px proxy, confirms once at full size, then calibrates the proxy from that one real measurement and lets the cheap search choose again — two full-resolution encodes are enough to land on the same quality an exhaustive search finds, which matters because a single full-size AVIF encode costs about two seconds. Trial encodes are memoized per format across both searches.

A few properties worth calling out:

  • Every advertised size is a real measurement, taken at the exact dimensions and quality that will be written, so converting a chosen proposal reproduces it byte for byte. Trial encodes go to a MemoryStream; nothing touches disk during the search.
  • Ranking is resolution first, then quality, then size. Facing an upload limit, a full-resolution result at quality 88 beats a downscaled one at 95 — which is what someone actually wants.
  • An impossible budget yields an empty list, not a garbage thumbnail. Quality never drops below 45, and nothing is shrunk below 16 px on its shorter side.
  • ICO and GIF are excluded from the search but remain ordinary conversion targets. Magick's ICO encoder hard-throws above 512 px per side, and its payload flips between BMP and PNG around 256 px, so encoded size is not monotonic in the scale factor; GIF quantizes to ≤256 colors (measured: ~750,000 colors → 76) while ignoring Quality entirely, so a badly degraded result would be advertised as "full quality". If those are the only enabled formats, the user gets a message instead of a pointless search.
  • The search reports each format as it starts, so the progress bar is determinate ("Checking AVIF (6/6)…") rather than a marquee. AVIF is by far the slowest; cancellation lands in about a quarter of a second.

Localizable dialog titles

Every dialog title in the app had always rendered in English, in every language. GetText.Extractor only recognizes qualified assignments in designer files (okButton.Text = "&OK"), so a form's own bare Text = "Settings"; never reached the translation catalog. All nine dialogs now set their title in the constructor instead, and the eight new msgids are translated into all four languages. Note that msgmerge fuzzy-matches these titles against the similarly worded menu items, so the merged entries arrive carrying & mnemonics and trailing ...; those were cleaned up, and the gotcha is documented in CLAUDE.md.

Documentation

Russian wording

The Convert menu is now Конвертация — a noun, matching Файл / Правка / Справка. Multi-size ICO is now consistently многоразмерный ICO: the menu item, dialog title, progress message, and status line said с несколькими размерами while the message boxes already used the short form.

@Menelion
Menelion merged commit 21d2051 into master Aug 21, 2026
1 check passed
@Menelion
Menelion deleted the fix-24 branch August 21, 2026 12:52
@Menelion Menelion added the enhancement Enhancement to an existing feature label Aug 21, 2026
@Menelion Menelion self-assigned this Aug 21, 2026
@Menelion Menelion added this to the Version 1.1.0 milestone Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Images restricted by file size

1 participant