Skip to content

Instantly share code, notes, and snippets.

@mcenirm
Created June 4, 2014 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcenirm/b1a045320edc18c97856 to your computer and use it in GitHub Desktop.
Save mcenirm/b1a045320edc18c97856 to your computer and use it in GitHub Desktop.
Wrapper script for jp2a that will attempt to convert other image formats to JPEG. Requires ImageMagick's convert (or compatible).
#!/bin/bash
JP2A=$(dirname "$0")/jp2a
declare -a jp2aopts
while [[ $# -gt 0 ]] ; do
case "$1" in
-) break ;;
--) shift ; break ;;
-*) jp2aopts+=( "$1" ) ; shift ;;
*) break ;;
esac
done
declare -a inputjpgs
for original in "$@" ; do
if [[ "${original}" == - || $( file "${original}" ) =~ ^JPEG\ image\ data ]] ; then
inputjpgs+=( "${original}" )
else
tmpjpg=$(mktemp --suffix=.jpg)
convert "${original}" "${tmpjpg}"
inputjpgs+=( "${tmpjpg}" )
fi
done
"${JP2A}" "${jp2aopts[@]}" "${inputjpgs[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment