Skip to content
alexander-srcPublic

About

Linux right-click "Convert to" file-manager menu and zero-dependency Rust CLI converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

86 Commits

Folders and files

Repository files navigation

convto

Zero-dependency Rust CLI and Linux file-manager context menu ("Convert to" and "Shrink / Optimize...") for converting, inspecting, and size-optimizing images, GIFs, audio, video, PDFs, structured data, archives, and documents from a right-click or terminal.

demo

What it does

Right-click one or more files in your Linux file manager, hover Convert to, and either pick a target format or click Shrink / Optimize... to reduce file size while keeping the highest quality that fits your budget. convto writes outputs atomically beside the source file without overwriting originals (photo.png, then photo (1).png; clip-shrunk.mp4 for shrinking), reserves unique output paths across parallel workers, and sends a desktop notification via notify-send.

Key details:

  • Single ~1.4 MB stripped binary (#![forbid(unsafe_code)], zero external crates, MSRV Rust 1.80).
  • Convert-time transforms for images, audio, video, and GIFs: --resize / --max-dim (cap longest edge or GIF width while maintaining even dimensions for H.264/VP9), --fps (0.1..=240), --audio-bitrate (128k, 192k, 320k, 1M), and --strip-metadata / --keep-metadata.
  • Interactive Shrink & Optimize dialog (native GTK4 / Libadwaita with kdialog/zenity fallback) with three modes: Target Size (10 MB, 500 KB, Discord/Email presets), Size % Wheel (slider + scroll-wheel spinbox), and Quality Wheel (10% to 100% + lossless-only toggle), plus GIF target choices (MP4, WebM, WebP, AVIF, MKV), mid-run Stop cancellation, and retry on error.
  • Named shrink profiles via --profile (or --preset): discord (10 MB), discord-nitro (50 MB), email (25 MB), web (1 MB, max 1920px), and thumbnail (250 KB, max 640px), with --max-dim overrides.
  • Binary-search image quality solver (JPEG, WebP, AVIF, JXL, lossless and quantized PNG, optional jpegoptim fast path for JPEG) plus two-pass exact-bitrate video/audio shrinking via ffprobe + ffmpeg and tiered-DPI Ghostscript PDF shrinking that preserves vector text.
  • convto info (alias probe) inspects PNG, JPEG (including APP1 EXIF presence and orientation), GIF, WebP, BMP, TIFF, ICO, QOI, PSD, Netpbm (P1..P6), SVG, AVIF/HEIC, WAV, FLAC, Ogg Opus/Vorbis, MP3 (ID3v2 + MPEG frame headers), MP4/MOV/M4A (moov -> mvhd/tkhd duration, timescale, and dimensions via box seeking), PDF (version and page count), JSONL/NDJSON (record count, top-level value types, and first-record keys), INI (section count, key count, and section names), ENV/dotenv (key count, export count, and variable names), XML (root element, element count, max depth, and XML declaration), ZIP/JAR/WHL/EPUB (tail-seek EOCD and Central Directory entry count, compressed/uncompressed bytes, and ratio), TAR (streaming POSIX ustar/GNU header walk reporting entries, regular files, directories, symlinks, and payload bytes), GZIP (flags, FNAME, MTIME, and trailer ISIZE), Zstandard (RFC 8878 content size, window size, single-segment flag, checksum, and dict ID), XZ (check type None/CRC32/CRC64/SHA-256 and tail footer/padding sanity), Bzip2 (BZh[1-9] block size 100 KB..900 KB), WebAssembly (\0asm version, LEB128 section counts, and custom section names via seeking), Apache Parquet (leading and trailing PAR1 magic and footer metadata length), SQLite 3 databases (100-byte header: page size including 1 -> 65536, write/read version, WAL vs rollback journal mode, page count, text encoding, schema cookie, user version, and application ID), native executables and libraries (ELF32/ELF64, Mach-O 32/64-bit, Mach-O Universal Fat, and PE32/PE32+ container format, architecture, and endianness), and fonts (TrueType, OpenType, WOFF, WOFF2 table counts) directly in pure Rust without requiring ffprobe, while flagging misnamed extensions (for example, WebP saved as .jpg) and optionally enriching video streams with ffprobe.
  • convto diff <file_a> <file_b> performs semantic structural diff across any pair of structured data files (json, jsonl/ndjson, yaml, toml, ini, env, xml, csv, tsv), including cross-format comparisons (config.yaml vs config.json), ignoring key ordering and formatting, with --format text|json|patch (shorthand --patch and optional --test-ops for guarded RFC 6902 JSON Patch generation that pipes directly into convto patch), --max-changes <N>, atomic -o/--out <file>, and exit codes 0 (equal), 1 (differences found), or 2 (usage/parse/IO error).
  • convto query [<expr>] <file|-> extracts, filters, groups and aggregates, sorts, slices, projects, and counts values from any structured data file (json, jsonl/ndjson, yaml, toml, ini, env, xml, csv, tsv) or stdin (-, with optional --from <fmt>) using dotted keys (package.version, $.server.port, catalog.book[0].@id), quoted bracket keys ($["weird.key"]), positive or negative array indices (items[0].name, items[-1]), wildcard projections (items[*].name), repeatable AND-combined --where predicates (==, !=, <, <=, >, >=, ~=), --group-by <field> with Kahan-compensated --sum/--avg and exact --min/--max (defaulting <expr> to $, emitting [{"key": ..., "count": ..., ...}] in deterministic first-seen order with a null bucket for missing/null keys), --select <f1,f2,...> field projection (preserving field order), --sort-by <field> + --desc (nulls last), --offset <N>, --limit <N>, --count, -r/--raw, --format json|yaml|toml|jsonl|csv|tsv|env|xml|raw, --compact, --sort-keys, --indent <1-8>, and exit codes 0 (found), 1 (missing path), or 2 (syntax/conflict/parse/IO error).
  • convto merge <base> <overlay>... deep-merges two or more structured data files across any of the 9 built-in data formats (base.yaml + prod.toml + .env), merging nested objects recursively left-to-right with --array-strategy replace|append|unique, --to <fmt>, --from <fmt>, --compact, --sort-keys, --indent <1-8>, and atomic -o/--out <path> writing (or stdout when omitted).
  • convto patch <doc|-> <patch> transactionally applies RFC 6902 JSON Patch operations (add, remove, replace, move, copy, test) with RFC 6901 JSON Pointers (~1, ~0, strict array indices, - array append) across all 9 structured data formats and stdin (-), accepting JSON, YAML, or TOML patch files, with --to/--format, --from <fmt>, --compact/--sort-keys/--indent, atomic -o/--out <path>, atomic -i/--in-place, dry-run --check, and exit codes 0 (applied), 1 (test mismatch, zero partial writes), or 2 (invalid patch, pointer, missing target, or self-move cycle).
  • convto redact <path|-> redacts secrets and sensitive fields across all 9 structured data formats and stdin (-) with --default-secrets/--presets (built-in secret key names and value prefixes like ghp_, github_pat_, sk-, AKIA, -----BEGIN ), case-insensitive --keys and --key-contains, explicit dot/JSON-Pointer --paths, custom --replacement, UTF-8-safe --keep-prefix <N>, zero-leak --report (text or --json), CI leak-scanning --fail-if-found (exit 1 on hit), --from/-t/--to/-o/--output, --pretty/--compact/--sort-keys, and a 128-level recursion depth guard.
  • convto flatten <path|-> and convto unflatten <path|-> convert between nested structured data and flat delimited key-value pairs (server.ports.0 = 8080, db.host = "localhost") across all 9 formats and stdin (-), supporting --delimiter <str>, --preserve-empty (for flatten), --no-arrays (for unflatten), --from <fmt>, --to/--format (json, yaml, toml, env, csv/tsv key,value rows, ini), atomic -o/--out <path> writes, 128-level depth guards, structural conflict detection, and a 10,000 array-index DoS cap on unflatten.
  • convto fmt <path>... canonically formats structured data files (json, jsonl/ndjson, yaml, toml, ini, env, xml, csv, tsv) atomically in place by default (skipping unchanged files to preserve mtime), or runs as a read-only CI gate with --check (exit 1 if any file would change), --diff (unified line diff without writing), or --stdout (single file to stdout), supporting --compact, --sort-keys, --indent <1-8>, --from <fmt>, -r/--recursive, --ext, --exclude, --json, and -q/--quiet.
  • convto stats <path>... computes schema and numeric summaries across structured data files (record/row or key counts, max nesting depth, per-column inferred types null/bool/int/float/string/array/object/mixed, non-null/null/unique counts, and exact min/max/mean/median for numeric columns), with streaming JSONL and CSV/TSV execution, --json, --from <fmt>, and -r/--recursive.
  • convto schema <path|-> infers a deterministic JSON Schema (Draft 2020-12) from any structured data file (json, jsonl/ndjson, yaml, toml, ini, env, xml, csv, tsv) or stdin (-), merging heterogeneous object records across arrays, JSONL, and CSV rows into unified properties, exact required lists, union type arrays (widening integer + number to number), and pure-Rust string format hints (date-time, date, uuid, uri, email, ipv4), with --title, --strict, --no-formats, --format json|yaml|toml, --from <fmt>, --compact, and atomic -o/--out <file>.
  • convto validate <path|->... checks syntax, structure, and optional Draft 2020-12 JSON Schema conformance (--schema <file>, accepting JSON, YAML, or TOML schemas) across all supported structured data formats (json, jsonl/ndjson, yaml, toml, ini, env, xml, csv, tsv) and stdin (-) without external tools, auto-detecting extensions (including .env and .env.*) or overriding with --from <fmt>, supporting type, required, properties, additionalProperties, items, enum, const, numeric/string/array/object bounds, format (date-time, date, uuid, uri, email, ipv4), allOf/anyOf/oneOf/not, 128-level depth guards, -r/--recursive, --ext, --exclude, --json (with schema and per-file violations: [{path, keyword, message}]), --fail-fast, -q/--quiet, and exit codes 0 (all valid), 1 (syntax or schema failures), or 2 (usage or invalid/missing schema error).
  • Recursive directory batching (-r/--recursive) with --ext extension filters, repeatable glob exclusions (--exclude supporting *, ?, and ** with directory subtree pruning), symlink-cycle protection, automatic skipping of nested --out-dir and --manifest paths, relative subdirectory preservation under --out-dir, race-free parallel execution (-j), aggregate --summary reports, and atomic JSON batch manifests (--manifest <file>).
  • Built-in structured data converter (json, jsonl/ndjson, yaml, toml, ini, env, xml, csv, tsv) with no external tools, streaming CSV/TSV/JSONL conversion paths, 128-level nesting guards across all parsers, YAML block scalars (|/>) and flow collections, TOML multiline strings and radix integers, INI sections and typed scalars, dotenv export / single-quoted / double-quoted multiline values (flattening nested objects with _ on .env output and rejecting non-object roots or flattened key collisions), XML 1.0 elements/attributes (@attr)/text (#text)/CDATA/entities/repeated sibling arrays, RFC 4180 CSV/TSV, and --compact, --sort-keys, and --indent <1-8> formatting options.
  • Archive repacking checks exact extract/pack backend availability before running (including during --dry-run), blocks path traversal (.., absolute paths, Windows drive prefixes), and rejects symlinks before repacking.
  • Built-in shell completions (convto completions bash|zsh|fish|powershell) and Unix roff manual page (convto man, bundled as convto.1 in release archives).

Supported formats

Family Inputs Targets Backend
Images png, jpg, webp, avif, heic, jxl, bmp, tiff, ico, svg, tga, psd, qoi, ppm png, jpg, webp, avif, jxl, gif, ico, tiff, bmp, pdf magick / convert, rsvg-convert, jpegoptim
GIF gif mp4, webm, webp, png, jpg, avif ffmpeg, magick
Audio mp3, wav, flac, ogg, opus, m4a, aac, wma, aiff, mka mp3, wav, flac, ogg, opus, m4a ffmpeg
Video mp4, mkv, webm, mov, avi, flv, wmv, mpg, 3gp mp4, mkv, webm, mov, gif, mp3, wav, opus ffmpeg
PDF pdf png, jpg, webp, txt pdftoppm (or magick / convert), pdftotext
Data json, jsonl, ndjson, yaml, toml, ini, env, xml, csv, tsv json, jsonl, yaml, toml, ini, env, xml, csv, tsv Built-in
Archives zip, tar, tar.gz, tar.zst, tar.xz, tar.bz2, 7z, rar zip, tar.gz, tar.zst, tar.xz, tar.bz2, tar, 7z tar, bsdtar, zip, unzip, 7z, unrar, zstd
Documents md, html, docx, odt, epub, rtf, txt pdf, html, md, docx, odt, txt pandoc, libreoffice

Install

Build from source (Rust 1.80+) and install desktop right-click menus:

cargo build --release --locked
install -Dm755 target/release/convto ~/.local/bin/convto
convto install

Prebuilt release archives (each bundling convto and convto.1) are published for Linux (x86_64 GNU/musl, aarch64), macOS (aarch64, x86_64), and Windows (x86_64).

Supported file managers (auto-detected by convto install, or pass --desktop dolphin|nautilus|nemo|thunar|all):

  • KDE Dolphin (Plasma 6 and 5): ~/.local/share/kio/servicemenus/convto-*.desktop (auto-runs kbuildsycoca6).
  • GNOME Files (Nautilus): ~/.local/share/nautilus-python/extensions/convto_nautilus.py (requires python-nautilus / nautilus-python; covers all 8 format groups including documents and normalizes extension aliases; restart Nautilus with nautilus -q).
  • Cinnamon Nemo: ~/.local/share/nemo/actions/convto-*.nemo_action.
  • XFCE Thunar: managed <!-- convto-managed --> entries in ~/.config/Thunar/uca.xml.

Remove all generated menus at any time without affecting your other custom actions:

convto uninstall

Enable shell completions or read the manual page:

# Bash
eval "$(convto completions bash)"

# Zsh
eval "$(convto completions zsh)"

# Fish
convto completions fish | source

# PowerShell
convto completions powershell | Out-String | Invoke-Expression

# View manual page
convto man | man -l -

CLI usage

# Convert images, media, PDFs, structured data, or archives
convto png photo.webp
convto webp *.png -q 85 --resize 1600 --strip-metadata
convto mp4 reaction.gif --fps 24
convto mp3 podcast.wav --audio-bitrate 192k --strip-metadata
convto png slides.pdf
convto yaml config.json
convto --sort-keys --indent 4 json events.jsonl
convto --compact --sort-keys json config.yaml
convto jsonl metrics.csv
convto json settings.ini
convto json .env
convto yaml catalog.xml
convto tar.zst backup.zip

# Recursively convert a directory tree with exclusions, summary, and JSON manifest
convto -r --ext png,jpg --exclude 'build/**' --exclude '*.tmp.png' -j 4 \
  --out-dir photos/converted --summary --manifest report.json webp photos/

# Shrink by target size, percentage, quality, or named profile
convto shrink clip.mp4 --profile=discord
convto shrink photo.png --profile=web --max-dim=1280 --to=webp
convto shrink report.pdf --target-size=2MB
convto shrink photo.jpg --percent=45
convto shrink photo.jpg --lossless
convto shrink --gui photo.png clip.mp4

# Inspect files (dimensions, EXIF, audio/MP4/PDF/data/ZIP/TAR/GZIP/Zstd/XZ/Bzip2/Wasm/Parquet/SQLite/ELF/Mach-O/PE/font headers)
convto info photo.jpg voice.wav clip.mp4 deck.pdf events.jsonl archive.tar app.wasm data.zst data.xz data.bz2 table.parquet app.sqlite3 ./convto
convto probe -r --exclude 'build/**' --json photos/

# Semantic structural diff across structured data formats (exit 0 equal, 1 diff, 2 error)
convto diff config.yaml config.json
convto diff --format json --max-changes 25 a.toml b.json
convto diff --patch --test-ops old.yaml new.toml -o changes.patch.json
convto patch old.yaml changes.patch.json --to toml

# Query, filter, group/aggregate, project, sort, slice, and count values across structured data formats or stdin (-)
convto query -r package.version Cargo.toml
convto query 'items[*].name' data.json
convto query '$' logs.jsonl --where status==200 --where latency_ms>=50 --sort-by latency_ms --desc --limit 10
convto query metrics.jsonl --where ok==true --group-by arch --avg wall_ms --min wall_ms --max wall_ms --sort-by avg
convto query metrics.csv --group-by region --sum revenue --format csv --sort-by sum --desc
cat events.jsonl | convto query - --from jsonl --group-by status --sort-by count --desc
convto query '$' users.csv --where user.role!=guest --select id,user.name,status
convto query '$' events.jsonl --where path~=/api --count
convto query -r 'catalog.book[0].@id' catalog.xml
convto query -r DATABASE_URL .env

# Deep-merge structured data overlays across formats (to stdout or atomic -o/--out file)
convto merge base.yaml prod.toml local.env -o merged.json
convto merge --array-strategy unique --sort-keys --to yaml base.json extra.json

# Apply RFC 6902 JSON Patch across structured formats atomically (exit 0 ok, 1 test failed, 2 error)
convto patch config.yaml changes.json -o config.patched.yaml
convto patch --in-place Cargo.toml bump.yaml
convto patch --check settings.json guard.patch.json
cat config.yaml | convto patch --from yaml --to json - changes.json

# Redact secrets and sensitive fields across structured formats or stdin (-)
convto redact .env
convto redact --default-secrets --keep-prefix 4 config.yaml -o config.safe.yaml
convto redact --keys email --paths db.password,/auth/token users.json
convto redact --default-secrets --report --json --fail-if-found secrets.toml

# Flatten nested documents into delimited key-value pairs and reconstruct with unflatten
convto flatten --delimiter _ --format env config.yaml
convto flatten --format csv --sort-keys config.json -o flat.csv
convto flatten --preserve-empty config.json | convto unflatten -
convto unflatten --no-arrays flat_ids.json -o nested.yaml

# Canonically format structured data files in place or gate CI with --check / --diff
convto fmt --sort-keys config.json settings.yaml catalog.xml
convto fmt --check -r --exclude 'build/**' ./configs
convto fmt --diff --indent 4 config.json

# Summarize schema, types, null/unique counts, and numeric stats (min/max/mean/median)
convto stats metrics.csv events.jsonl
convto stats --json config.toml

# Infer a Draft 2020-12 JSON Schema from any structured data file or stdin (-)
convto schema --title Users --strict users.jsonl -o users.schema.json
convto schema --format yaml --no-formats metrics.csv
cat payload.json | convto schema --title Event -

# Validate syntax and enforce Draft 2020-12 JSON Schemas across files or stdin (-) (exit 0 valid, 1 invalid, 2 error)
convto validate config.json settings.yaml .env catalog.xml
convto validate --schema users.schema.json users.yaml
convto validate -r --schema config.schema.yaml --json ./configs
cat payload.yaml | convto validate --schema event.schema.json --from yaml -
convto validate --from xml --fail-fast --quiet payload.txt

# Pass -- before filenames starting with -, or inspect per-command help
convto jpg -- -leading-dash.png
convto shrink --help

# Inspect targets and installed backends
convto targets photo.webp
convto doctor

Useful convert flags: --out-dir <dir>, -r/--recursive, --ext <exts>, --exclude <glob>, --overwrite, --force (re-encode same format), --delete-source, --quality <1-100>, --resize <px> (--max-dim), --fps <rate>, --audio-bitrate <rate>, --strip-metadata (--strip), --keep-metadata, --compact, --sort-keys, --indent <1-8>, -j/--jobs <1-128>, --dry-run (side-effect free; does not create --out-dir), --summary, --manifest <file>, --notify, --json.

Useful shrink flags: --target-size <size>, --percent <1-99>, --quality <1-100>, --lossless, --profile discord|discord-nitro|email|web|thumbnail, --to <fmt>, --hevc, --max-dim <px>, --preset fast|medium|slow|<profile>, --no-two-pass, --keep-metadata, --in-place, -r/--recursive, --ext <exts>, --exclude <glob>, --summary, --manifest <file>, --gui, --json.

Value-taking long options accept both --flag value and --flag=value, while boolean flags reject =value. --json works across convert, shrink, fmt, stats, validate, info, targets, formats, and doctor (with --format json on diff and query) for scripting, and batch --json output includes "source" on both successes and per-file error records.

Limitations

  • Media, PDF, archive, and document conversions shell out to system tools (magick, ffmpeg, pdftoppm, tar/7z, pandoc/libreoffice). Run convto doctor to see what is installed on your machine.
  • In KDE Dolphin, KIO service menus filter by MIME family rather than hiding the current file's own format inside the submenu (so PNG (.png) still appears when right-clicking a .png, and convto skips it unless --force is passed). Nautilus's Python extension hides the active format (including aliases such as .jpeg and .yml) dynamically.
  • The built-in YAML parser covers standard block/flow mappings, sequences, and literal/folded block scalars; it does not implement anchors/aliases (&a/*a), multi-document streams, or custom tags.
  • Pure-Rust PDF page counting scans uncompressed /Type /Page markers with a /Type /Pages /Count fallback for compressed object streams; encrypted PDFs or files larger than 16 MB report version only.
  • The CLI works on Linux, macOS, and Windows; desktop right-click menu installation targets Linux file managers (Dolphin, Nautilus, Nemo, Thunar).

License

MIT. See LICENSE.

About

Linux right-click "Convert to" file-manager menu and zero-dependency Rust CLI converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages