Linux批量转图,CMYK转RGB

使用方法:解压后sh imageconvert.sh 输入路径 输出路径 定宽宽度x定高高度
定高高度和定宽宽度按照原图的形状,设置值较小一端,另一端按比例缩放
首先要安装ImageMagic
3.0新增加水印

使用色域空间的ICC在附件中。

代码如下:


#/bin/bash
## author:wangjianwu
#version 0.1
if [ ! -x "${1}" ] || [ ! -x "${2}" ] || [ -z ${3} ] || [ -z ${4} ]; then
echo "maybe file not found or command error!"
echo "help:command inputdir outputdir size density [w|h|wh]"
exit -1
fi

CONVERT="convert"
export CMYK_ICC=CoatedFOGRA39.icc
export RGB_ICC=AdobeRGB1998.icc
ext="jpg"

bwidth=`echo "${3}"|awk -F 'x' '{print $1}'`
bheight=`echo "${3}"|awk -F 'x' '{print $2}'`
inpath=${1}
pathPosition=${#inpath}
echo "${pathPosition}"
find ${1} -type f | while read line
do
fext=${line##*.}
if [ "$ext" != "$fext" ]
then
continue
fi
imageFilePath=`echo ${line} | cut -c ${pathPosition}-${#line}`
imageOutputPath="${2}${imageFilePath}"
op="${2}"
#ps=`echo $str|tr '\/' ' '|tr -s ' '`
ps=`echo ${imageFilePath} | sed 's/\// /g'`
endps=`echo ${imageFilePath} | awk -F "\/" '{print $NF}'`
for keystr in `echo ${imageFilePath} | sed 's/\// /g'`
do
op="${op}/${keystr}"
if [ "$keystr" = "$endps" ]
then
continue
fi
if [ ! -x ${op} ]
then
mkdir ${op}
fi
done
#get width and heigth
width=`identify -format "%w" ${line}`
height=`identify -format "%h" ${line}`
#echo "${width}========${height}"
if [ ! -z ${5} ] && [ "${5}" == "w" ]
then
echo "xxxX"
bsize="${bwidth}x${height}"
elif [ ! -z ${5} ] && [ "${5}" == "h" ]
then
echo "yy"
bsize="${width}x${bheight}"
elif [ ! -z ${5} ] && [ "${5}" == "wh" ]
then
echo "xxy"
bsize="${bwidth}x${bheight}"
elif [ $width -gt $height ]
then
# echo "width>height"
bsize="${width}x${bheight}"
elif [ $width -lt $height ]
then
# echo "width<height"
bsize="${bwidth}x${height}"
else
if [ $bwidth -gt $bheight ]
then
bsize="${bwidth}x${bwidth}"
else
bsize="${bheight}x${bheight}"
fi
fi

convertCommand="${CONVERT} -density ${4} -units PixelsPerInch ${line} -resize ${bsize} -profile ${CMYK_ICC} -profile ${RGB_ICC} ${imageOutputPath}"

echo ${convertCommand}
${convertCommand}
echo "${width}x${height}"
done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值