#!/bin/bash # # convert (essentially from AdobeRGB or CMYK) to sRGB jpg # and optionally resize # # # From a IM Forum discussion... # http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=16464&start=15 # # Curtisy of Albert25 -- 26 June 2010 # ### # paths to profile file locations srgb=/docs/photos/icc/sRGB.icm cmyk=/docs/photos/icc/USWebCoatedSWOP.icc # defaults outdir=. debug= # read options while getopts "dvho:s:a:" opt do case $opt in "d|v" ) debug=1;; # verbose is same as debug for now "s" ) size=$OPTARG;; "o" ) outdir=$OPTARG;; "a" ) add_options=$OPTARG;; "h" ) cat </dev/null [ -n "$debug" ] && echo " resize = $resize" if [ -s "$profile" ]; then # we have an embedded profile, so ImageMagick will use that anyway [ -n "$debug" ] && echo " convert with embedded profile $f" convert "$f" -profile "$srgb" +profile '*' $resize $add_options "$out" \ && echo -e "\tOK $out" else # no embedded profile in source if identify -format "%r" "$f" | grep CMYK >/dev/null ; then # CMYK file without embedded profile [ -n "$debug" ] && echo " convert cmyk without embedded profile $f" convert "$f" -profile "$cmyk" -profile "$srgb" +profile '*' $resize $add_options "$out" \ && echo -e "\tOK $out" # alternative would be #convert "$f" -colorspace RGB -resize $size "$out" else # No profile and not CMYK. Probably already in RGB. Just resize [ -n "$debug" ] && echo " resizing only $f" convert "$f" $resize $add_options "$out" \ && echo -e "\tOK $out" fi fi [ -f "$profile" ] && rm "$profile" done