Skip to content

Pictures: compress pictures to a target resolution - #513

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
NikitkaRa:compress-pictures
Oct 14, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
NikitkaRa:compress-pictures

Conversation

@NikitkaRa

Copy link
Copy Markdown
Contributor

Summary

  • New picture.compress {ppi?: 330|220|150|96 (default 220), deleteCropped?: bool (default true), all?: bool, ids?} → {pictures, before, after}.
  • Downsampling: each PNG/JPEG/BMP/TIFF/WebP picture goes down to the pixels its shown size needs at that ppi. With the crop kept, the visible part is what gets the full resolution.
  • Formats: JPEG stays JPEG (quality 85); the others become PNG. SVG, EMF/WMF, GIF and linked pictures are left alone.
  • Delete cropped areas: cuts the cropped-away pixels and resets the crop. Padding crops (negative values) are kept.
  • No growth: a picture is replaced only when the result is smaller or a crop was removed. A picture shared by shapes at the same size and crop is compressed once.
  • Originals: an original nothing else uses is dropped, so the .deckcraft and .pptx files really shrink. One still used by a picture that wasn't compressed stays. One undo step restores everything.
  • UI: Picture Format › Adjust › Compress Pictures opens PowerPoint's options: Apply only to this picture, Delete cropped areas of pictures, and HD / Print / Web / E-mail resolution. A Compress button runs it, and the status bar reports the KB saved.
  • Docs: parity checklist row M → D; removed from gaps.md "Smaller missing rows".

No issue tracks this; it's a docs/gaps.md item.

Test plan

  • cargo xtask ci (fmt, clippy, test, assets, layers, wasm)
  • Unit tests (cmd::compress):
    • 2000 px shown at 1 in → 150 px at 150 ppi; an already-small picture or an SVG is left alone
    • delete cropped areas gives the visible half at the right size with crop reset; keeping the crop scales the whole image
  • compress_pictures_shrinks_the_file_and_keeps_shared_originals:
    • a noisy 1600² PNG shown 2 in is 300² at 150 ppi, the original media is gone, and the .pptx is more than 4× smaller
    • undo restores the original
    • compressing one of two pictures sharing media keeps the original for the other; all: true then compresses both
    • an out-of-range ppi is an error
  • deckcraft-cli run --in 45545_Comment.pptx --cmd 'picture.compress={"ppi":96,"all":true}': a third-party deck whose pictures are already small (a PNG and a WMF) is left as it was
  • Not checked: how the options popup looks on screen. The box can't run the app's display (libxkbcommon-x11 isn't installed)

Picture Format › Adjust gains Compress Pictures, with PowerPoint's
options: HD 330, Print 220, Web 150 or E-mail 96 ppi, apply to the
selected pictures or all, and delete cropped areas. The new
picture.compress command downsamples each PNG, JPEG, BMP, TIFF or WebP
picture to the pixels its shown size needs at that resolution (JPEG
stays JPEG at quality 85, the rest become PNG), cuts away cropped areas
when asked, and only replaces a picture when the result is smaller or a
crop was removed. Originals nothing else uses are dropped so the saved
file shrinks; one shared with a picture that wasn't compressed stays.
One undo step restores everything.

Co-authored-by: Cursor <cursoragent@cursor.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 70a9a5b into storytold:main Oct 14, 2026
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 14, 2026
picture.compress decided which originals were still in use by scanning JSON
keys, which missed artistic-effect originals (and the embedded-font shape it
assumed no longer exists), so compressing a picture whose bytes were also
another picture's artistic original deleted media still in use. It now uses
the engine's typed media walker (media_refs::presentation_media).

Decoding is capped: the header's size is read first and pictures over 64 MP
are left alone, and the decoder runs with image::Limits (512 MiB allocation),
instead of decoding up to 400 MP before checking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 14, 2026
# Conflicts:
#	crates/engine/src/cmd/mod.rs
#	crates/ui-egui/src/ribbon.rs
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution, @NikitkaRa! It has landed on main and will ship in the next DeckCraft release.

If you haven't already, please come join us on Discord: https://discord.gg/artcraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants