Skip to content

Feature idea: bulk-convert media library assets to WebP/AVIF in place #24

Description

@ghassenlarnaout

Motivation

The Assets panel has no way to optimize images already in a project — everything gets served at its original size/format. A quick way to shrink public/src images (e.g. ones dragged in straight from a phone/camera) would cut page weight without leaving the app.

Proposed feature

  • A "select" mode in the Assets panel: checkboxes on every asset tile, plus a "select all" toggle.
  • Bulk "Convert to WebP" / "Convert to AVIF" for whatever images are selected (also available per-file from the "⋯" menu) — re-encodes at 95% of the original resolution and 95% quality.
  • Conversion replaces the original in place (same folder/name, new extension) rather than creating a duplicate, and rewrites every reference to it project-wide so pages don't break:
    • a public/ asset's served URL (/img/hero.jpg/img/hero.webp), wherever it's quoted or bare (JS/astro attributes, markdown links, CSS url())
    • a src/ asset's import specifier (import hero from '../assets/hero.jpg'.../hero.webp)
  • Bulk delete alongside it, since you're already selecting multiple assets.

Implementation notes (from a working local prototype)

No new dependency needed — Electron's own Chromium can already resize and encode to WebP/AVIF via <canvas>.toBlob(), so this is renderer-side canvas work plus a small main-process handler that writes the file and does the reference rewrite. Confirmed both codecs encode successfully in the Electron 33 build this repo pins.

Known gap: a content-collection frontmatter field that names an image via a relative string path (Astro's image() schema helper) isn't rewritten — only import specifiers and rooted public URLs are covered right now.

Happy to open a PR with this if it's a direction you'd want — wanted to check appetite first since it touches every reference in a project.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions