Skip to content

Instantly share code, notes, and snippets.

@Kedrigern
Created September 23, 2011 20:50
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 Kedrigern/1238406 to your computer and use it in GitHub Desktop.
Save Kedrigern/1238406 to your computer and use it in GitHub Desktop.
My small but smart script for batch converting (and other manipulation) images to cmyk colorspace.
#!/bin/bash
# What do: Converting, manipulating etc. jpegs to CMYK colorspace
# Script is absolutly free/libre, but no guarantee.
# Author: Ondřej Profant
function 2cmyk {
echo -e "[info]\tThis operation needs a lot of CPU resources. Probably will take a long time."
for i in *.jpg ; do
mv $i ${i%.jpg}rgb.jpg
convert -depth 8 -colorspace cmyk -alpha Off ${i%.jpg}rgb.jpg ${i%.jpg}cmyk.jpg
done;
}
function fin {
case $1 in
rgb)
for i in *rgb.jpg; do
mv $i ${i%rgb.jpg}.jpg
done;
;;
cmyk)
for i in *cmyk.jpg; do
mv $i ${i%cmyk.jpg}.jpg
done;
;;
*)
usage
exit;
;;
esac;
}
function del {
echo "Are you sure you want to delete all $1 files? (y/n)";
read x ;
if [ $x = "y" ] ; then :
case $1 in
rgb) rm *rgb.jpg ;;
cmyk) rm *cmyk.jpg ;;
*) usage;;
esac;
else
exit;
fi;
}
function checkPDF {
identify -verbose ${1} | grep Colorspace
}
function usage {
echo "USAGE:"
echo -e "\t$0 convert\t\tconvert all *jpg in folder"
echo -e "\t$0 check [file]\tcheck pdf colorspace (file can be pdf)"
echo -e "\t$0 replace\t\treplace rgp-*.jpg by cmyk-*.jpg"
echo -e "\t$0 fin [rgb/cmyk]\tdelete colorspace sufix"
echo -e "\t$0 del [rgb/cmyk]\tdelete files with sufix"
}
# == MAIN ==
if convert -version > /dev/null ; then :
else
echo "ImageMagick mising";
exit;
fi;
case $1 in
con*)
2cmyk
echo -e "[info]\t Your old pics be renamed, new cmyk was created. For finish use:"
echo -e "\t$0 fin [cmyk/rgb]"
;;
check) checkPDF $2 ;;
info) checkPDF $2 ;;
fin*) fin $2 ;;
del) del $2 ;;
*) usage ;;
esac;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment