`
jianwwpro
  • 浏览: 28692 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics