Skip to content

Instantly share code, notes, and snippets.

@claunia
Created January 12, 2025 14:07
Show Gist options
  • Save claunia/7ee51a7d5bcd25056f5b829228e57555 to your computer and use it in GitHub Desktop.
Save claunia/7ee51a7d5bcd25056f5b829228e57555 to your computer and use it in GitHub Desktop.
Losslessly convert all PNGs in current folder to JPEG-XL preserving EXIF and mtime. (Bash script)
#!/bin/bash
if [[ -n $(shopt -s nullglob; echo *.png) ]]; then
for i in *.png
do k="${i%.png}.jxl"
cjxl -q 100 -e 10 "$i" "$k"
done
if [[ -n $(shopt -s nullglob; echo *.jxl) ]]; then
for k in *.jxl
do i="${k%.jxl}.png"
exiftool -m -overwrite_original -api compress=1 -tagsfromfile "$i" "$k"
touch -r "$i" "$k"
rm "$i"
done
fi
fi
if [[ -n $(shopt -s nullglob; echo *.PNG) ]]; then
for i in *.PNG
do k="${i%.PNG}.JXL"
cjxl -q 100 -e 10 "$i" "$k"
done
if [[ -n $(shopt -s nullglob; echo *.JXL) ]]; then
for k in *.JXL
do i="${k%.JXL}.PNG"
exiftool -m -overwrite_original -api compress=1 -tagsfromfile "$i" "$k"
touch -r "$i" "$k"
rm "$i"
done
fi
fi
if [[ -n $(shopt -s nullglob; echo *.png.xmp) ]]; then
for i in *.png.xmp
do k="${i%.png.xmp}.jxl.xmp"
if [[ -f "${i%.png.xmp}.jxl" ]]; then
mv "$i" "$k"
fi
done
fi
if [[ -n $(shopt -s nullglob; echo *.PNG.xmp) ]]; then
for i in *.PNG.xmp
do k="${i%.PNG.xmp}.JXL.xmp"
if [[ -f "${i%.PNG.xmp}.JXL" ]]; then
mv "$i" "$k"
fi
done
fi
find . -empty -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment