transcode-jpeg-to-jxl-lossless
Use when the user wants to archive a JPEG-only library as JPEG XL — losslessly transcodes JPEG to .jxl, preserving the original bitstream for byte-exact recovery, with a dry-run preview and a byte-savings report (~15–25% reduction). Prefer this over the general-purpose `to-jxl` skill whenever the sources are exclusively JPEG and archival is the goal. Triggers - "archive my JPEGs as JXL", "shrink this photo library losslessly", "JPEG to JXL without quality loss".
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- transcode-jpeg-to-jxl-lossless
- description
- Use when the user wants to archive a JPEG-only library as JPEG XL — losslessly transcodes JPEG to .jxl, preserving the original bitstream for byte-exact recovery, with a dry-run preview and a byte-savings report (~15–25% reduction). Prefer this over the general-purpose `to-jxl` skill whenever the sources are exclusively JPEG and archival is the goal. Triggers - "archive my JPEGs as JXL", "shrink this photo library losslessly", "JPEG to JXL without quality loss".
- allowed-tools
- Bash(cjxl *), Bash(djxl *), Bash(command *), Bash(find *), Bash(sh *), Bash(awk *), Bash(wc *), Bash(du *), Bash(tail *), Bash(tee *), Read, Write
03 SKILL.md 正文
Losslessly Transcode JPEG to JPEG XL
Walk a directory of JPEG files and convert them to JPEG XL (.jxl) format using lossless encoding. cjxl automatically detects JPEG bitstream and preserves it without re-compression. Reports byte savings; explains how to recover the original JPEG if needed.
When to use
- Archiving JPEG photo libraries to save space (typically 15–25% reduction) without image degradation.
- Preparing a photo collection for long-term storage where compatibility with JPEG is not required.
- Building a smaller-footprint JXL archive that can still yield the original JPEG byte-exact via
djxl.
For non-JPEG sources, or for lossy/web-quality JXL encodes, use to-jxl — this skill deliberately handles only the JPEG-archival case.
Inputs to gather
- Source directory — folder containing JPEG files (
.jpgor.jpeg). Default: current directory. - Recursive? Ask whether to process subdirectories. Default: no (flat, current folder only).
- Output location — optional. Default: same directory as originals (
.jxlfiles sit alongside.jpg). - Dry run first? Recommend a preview pass showing the count and byte savings estimate, before committing to the conversion.
Procedure
1. Check tooling
command -v cjxl >/dev/null || {
echo "cjxl not installed — see the image-ops-install-deps skill" >&2
exit 1
}
2. Preview
Show the user what will happen. Capture the original total into a variable — step 4 needs it to compute savings, and re-measuring the directory afterwards would count the new .jxl files too.
Set the depth limit once, from the answer to "recursive?" in the inputs:
maxdepth="-maxdepth 1" # non-recursive
maxdepth="" # recursive — omit the flag entirely
# Count JPEGs in scope
find "$target" $maxdepth -type f \
\( -iname '*.jpg' -o -iname '*.jpeg' \) | tee /tmp/jpegs.txt | wc -l
# Original total, in bytes (not human-readable — it has to be arithmetic later)
ORIG_BYTES=$(find "$target" $maxdepth -type f \
\( -iname '*.jpg' -o -iname '*.jpeg' \) -exec wc -c {} + \
| awk '$NF == "total" { next } { s += $1 } END { print s+0 }')
Skipping the total lines matters: -exec ... + batches its arguments, so a large tree produces one total line per batch and naively summing every line would double-count.
wc -c totals exact bytes; du rounds to block size and would skew the savings figure on a library of small files.
Print:
- Number of JPEG files found.
- Total original size.
- Estimated output size (advise 20% reduction as a rough baseline).
- Confirm before proceeding.
3. Transcode
Use -d 0 (lossless) and a reasonable effort (suggest 6–7 for balance):
find substitutes only the literal token {}. There is no {.} extension-stripping placeholder — that is GNU parallel syntax, and find would pass the literal string {.}.jxl, funnelling every file in the tree into one output that each conversion overwrites. Build the output name inside a shell instead, reusing the $maxdepth set in step 2:
: > "$failed_log"
find "$target" $maxdepth -type f \
\( -iname '*.jpg' -o -iname '*.jpeg' \) \
-exec sh -c '
for f do
cjxl -d 0 -e 7 "$f" "${f%.*}.jxl" || echo "$f" >> "$0"
done
' "$failed_log" {} +
(The -d 0 flag ensures lossless encoding. Effort 7 balances speed and compression. Effort 9 is slower but slightly smaller; only recommend if the user has time.)
$failed_log collects every non-zero cjxl exit. find -exec does not propagate per-file status, so without this file a failed transcode is silently invisible in the step 4 report.
4. Verify and report
After transcoding:
# Count JXL files created
find "$target" $maxdepth -type f -iname '*.jxl' | wc -l
# Total size of the new JXL files, in bytes
JXL_BYTES=$(find "$target" $maxdepth -type f -iname '*.jxl' -exec wc -c {} + \
| awk '$NF == "total" { next } { s += $1 } END { print s+0 }')
# Bytes saved — an explicit subtraction against the step 2 figure
awk -v o="$ORIG_BYTES" -v n="$JXL_BYTES" 'BEGIN {
printf "original: %.1f MB\njxl: %.1f MB\nsaved: %.1f MB (%.1f%%)\n",
o/1048576, n/1048576, (o-n)/1048576, (o ? (o-n)*100/o : 0)
}'
Do not substitute du -ch "$target" for this. At this point the directory holds both the originals and the new .jxl files, so it measures the sum of the two, not the saving. The saving only exists as the difference between the step 2 figure and the step 4 figure.
Print:
- Files successfully transcoded.
- Original total size vs. new total size.
- Bytes saved and percentage reduction (from the
awkabove). - Any failures — print the contents of
$failed_log, and say "none" only when that file is empty.
5. Explain recovery path
Inform the user:
If you ever need to recover the original JPEG bitstream byte-exact (for legal/archival purposes), run:
djxl archive.jxl recovered.jpgThis works because
cjxldetected and preserved the original JPEG structure. Reconstruction is triggered by the.jpgoutput extension — there is no--jpegflag in current libjxl. If the.jxlcarries no reconstruction data,djxlreports an error rather than quietly writing a re-encoded approximation, so a successful run is itself the proof of byte-exactness.
Output / side effects
.jxlfiles created in the source directory (or user-specified output folder).- Original
.jpgfiles remain untouched. - No backup is created; if the originals must be preserved, the user should copy them first.
Notes
- Lossless JPEG preservation:
cjxlauto-detects JPEG bitstreams and preserves them exactly. This is whydjxlcan recover the original — it's not a re-encoded approximation. - Effort 7 vs. 9: Effort 7 compresses in seconds per image; effort 9 can take minutes. For batch workflows, 7 is recommended. Use 9 only if compression size is the overriding concern.
- Size savings: Typical JPEG → JXL lossless reduction is 15–25%, depending on the original JPEG quality. Do not oversell — some JPEGs may compress only 5–10%.
- Selective transcoding: If you want to skip already-small files or transcode only above a size threshold, filter the find output (e.g.,
-size +100kfor files larger than 100 KB). - Do not delete the original JPEG files automatically. Let the user confirm removal after verifying the JXL output.
- Depends on
libjxl-tools(apt install libjxl-toolson Debian/Ubuntu,brew install jpeg-xlon macOS). Useimage-ops-install-depsrather than installing by hand.
04 同仓库更多 Skills
no-description
暂无简介
good-skill
Fixture skill that satisfies every rule.
broken-link
Links to a reference file that does not exist.
Bad_Name
Name violates the kebab-case rule and does not match the directory.
skill-authoring
Write, review, and validate portable agent skills in SKILL.md format. Use when creating a new skill, editing an existing one, or asked whether a skill follows the Agent Skills spec.
weigh-bags
Record scale readings for each bag — empty (tare), outbound, current, final — and reconcile them against the itemised inventory to find unaccounted weight. Use when the user gives a bag weight, says how heavy something is, weighs their luggage, or asks how close to the limit they are. Appends to bags.yaml and runs scripts/reconcile.py.