Skip to content

Add convert-png-jpeg CLI task to convert non-transparent PNGs to JPEG in-place#1526

Open
naaaaaaaaaaaf wants to merge 1 commit into
kancolle.social-latestfrom
codex/convert-non-transparent-png-to-jpeg
Open

Add convert-png-jpeg CLI task to convert non-transparent PNGs to JPEG in-place#1526
naaaaaaaaaaaf wants to merge 1 commit into
kancolle.social-latestfrom
codex/convert-non-transparent-png-to-jpeg

Conversation

@naaaaaaaaaaaf
Copy link
Copy Markdown

Motivation

  • Provide a maintenance tool to convert non-transparent PNG media to JPEG to reduce storage and bandwidth while preserving existing URLs and S3 keys.
  • Allow safe, resumable, and bounded runs with --limit and --min-id options and a --dry-run preview mode.
  • Use libvips for efficient image processing and avoid reprocessing transparent images.

Description

  • Adds a new CLI command convert-png-jpeg under Mastodon::CLI::media with options --limit, --min-id, and --dry-run and documentation in long_desc.
  • Queries MediaAttachment records with file_file_name ending in .png, optionally resumes from min_id and limits the number processed with limit.
  • Uses Vips::Image to detect an alpha channel and skips transparent images, converts non-transparent images to JPEG (Q: 85) into a Tempfile, and assigns the tempfile to the attachment while updating file metadata before saving.
  • Tracks and logs counts for processed, converted, skipped transparent, and skipped missing files, and rescues Vips::Error to log processing errors.

Testing

  • Ran the test suite with bundle exec rspec, and the test suite passed.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant