optimize-jpeg
Skill21 starsChanged 7 days agoMITView on GitHub
Use when the user wants to shrink JPEG files — losslessly with `jpegoptim` (~5–15% reduction, no re-encode) or with re-compression via `mozjpeg` (~10–15% better than libjpeg-turbo at the same visual quality). Web-prep workhorse for photo libraries.
In this repository28 other files it gives its agents.
- ai-graphicsSkill
- auto-deskewSkill
- auto-toneSkill
- auto-white-balanceSkill
- batch-set-copyrightSkill
- check-model-pricingSkill
- convert-to-avifSkill
- fast-resizeSkill
- fast-thumbnailSkill
- from-jxlSkill
- images-to-pdfSkill
- install-depsSkill
- new-projectSkill
- new-workflowSkill
- open-workspaceSkill
- optimize-pngSkill
- pdf-extract-embedded-imagesSkill
- pdf-to-imagesSkill
- read-metadataSkill
- scrub-metadataSkill
- set-metadataSkill
- svg-to-rasterSkill
- to-jxlSkill
- transcode-jpeg-to-jxl-losslessSkill
- upscale-imageSkill
- vectorizeSkill
- web-readySkill
- workspace-setupSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Do not use this skill when:
- Very specific: line 36
Verify the relevant binary.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Optimize JPEG
Squeeze JPEG file size. Two modes:
- lossless (default) —
jpegoptim --strip-all. Repacks Huffman tables and strips metadata. No re-encode, no quality change. - recompress —
mozjpeg(cjpeg-mozjpeg). Re-encodes with better quantisation tables; 10–15% smaller than libjpeg-turbo for the same SSIM. Quality flag controls trade-off.
When to use
- Web-prep: photo galleries, blog images, anything destined for upload.
- Archive squeeze: lossless mode is the no-regret option for any JPEG-heavy folder.
- Pre-step inside
web-readyorchestrator.
Do not use this skill when:
- Source is PNG → use
optimize-png. - Source is HEIC/RAW/TIFF — pipe through
web-ready(or convert first). - The JPEG is already heavily compressed (<70% quality estimate) — recompress will visibly degrade.
Inputs
- Input — file or directory. Required.
- Mode —
lossless(default) orrecompress. - Recursive —
--recursivefor directory descent. - In-place — default.
--output-dir <path>to write copies. - Quality (mode=recompress) —
cjpeg-mozjpeg -quality N. Default82(web-quality).90for archival;75for aggressive web compression. - Strip metadata — default
onfor both modes. EXIF/IPTC/XMP gone. Use--keep-metadatato preserve. - Progressive — default
on. Smaller files + better perceived load.--baselineto disable for compatibility with very old decoders.
Procedure
- Verify the relevant binary.
which jpegoptimfor lossless;which cjpeg-mozjpeg(or fallbackwhich cjpeg) for recompress. If missing, point atinstall-deps. - Enumerate inputs (JPEG/JPG only — skip with note).
Lossless (jpegoptim):
jpegoptim --strip-all --all-progressive [--dest <out-dir>] "<input>"--all-progressiveforces progressive output (smaller).--strip-allremoves EXIF/IPTC/XMP/comments. Drop these if--keep-metadatawas set.Recompress (mozjpeg):
mozjpeg's CLI is decode-then-encode, so for in-place behaviour:
djpeg "<input>" | cjpeg-mozjpeg -quality <q> -progressive [-optimize] > "<output>"Or use
jpegtran-mozjpegfor lossless transforms when only metadata stripping + Huffman repack is desired (essentially a faster jpegoptim).For batch, parallelise with
xargs -P <ncpu>.- Sanity-check: any output file >95% of input size in recompress mode — keep the original instead. cjpeg-mozjpeg occasionally inflates already-optimised inputs.
Output
- Optimised JPEGs at the resolved paths.
- Summary:
- Files processed / skipped / failed / kept-original (where recompress would have inflated).
- Total:
<orig-MB>→<new-MB>(<pct>%saved). - Visible-quality flag: if recompress was used and the source had a quality estimate <75 (via
identify -format "%Q"), surface a warning per file.
Notes
- mozjpeg is a drop-in libjpeg-turbo replacement with smarter trellis quantisation. It's slower than libjpeg-turbo by ~3× — fine for web-prep, not for thumbnail generation.
- For "I just want it smaller, don't touch quality": always use
losslessmode. Free win. - The orchestrator (
web-ready) defaults to: resize first, then encode WebP/AVIF, fall back to mozjpeg for JPEG output. This skill exists to do JPEG-only optimisation without that pipeline.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

