Third Party > Other Utilities

Shell script for converting progressive JPEGs to baseline

<< < (2/2)


--- Quote from: gevaerts on August 24, 2018, 04:17:08 PM ---Just for the record, newlines are perfectly valid in filenames, so that script is still breakable :)

--- End quote ---

See the canonical response for issues with iterating the output of find here:

--- Quote ---If you're using bash, then you have two additional options. One is to use GNU or BSD find's -print0 option, together with bash's read -d '' option and a ProcessSubstitution:

--- Code: ---while IFS= read -r -d '' file; do
  some command "$file"
done < <(find . -type f -name '*.mp3' -print0)
--- End code ---

--- End quote ---

Are you using bash as your shell? If so I would drop the backticks because of this:

I would rewrite the script to make it a little more solid like this:

--- Code: ---#!/usr/bin/env bash
function process_jpeg()
idout="$(identify -verbose "$img" | grep -i interlace | grep -i none)"

if [[ -z "$idout" ]]
echo "-------------------------"
echo "$img is progressive"
echo "....making copy of original with .prog extension"
/bin/cp -f "$img" "$img.prog"
echo "....converting to baseline"
convert "$img" -interlace none "$img"
echo "....done!"

command -v identify >/dev/null 2>&1 || { echo >&2 "identify is required, but not installed.  Aborting."; exit 1; };

while IFS= read -r -d '' file; do process_jpeg "$file"; done < <(find "$PWD" -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0)

--- End code ---

I also highly recommend using

Edit: Just realised this was from 2018... time to make coffee

Thanks for the rewrite and the additional information and tools bobba_mosfet. I'll update the wiki.


[0] Message Index

[*] Previous page

Go to full version