ImageMagic---convert(图片格式转换)
官方帮助文档:http://http://www.imagemagick.org/Usage/basics/
优秀分支GM
http://www.graphicsmagick.org/
1.格式转换,支持JPG, BMP, PCX, GIF, PNG, TIFF, XPM和XWD等类型,基本上gimp支持的格式ImageMagick都支持
convert
convert
下面提供批量转格式脚本,供大家参考
#####################################################
#!/bin/bash
#To batch convert pictures
#Made by liujun, liujun_live@msn.com, 20140820
#####################################################
# Source function library.
. /etc/init.d/functions
#Export PATH
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
#Define variables
Format_From=jpg
Format_To=gif
Directory_From=/tmp
Directory_To=/tmp/test
Size=
Pictures=$(ls $Directory_From/*.$Format_From)
#Create the target directory
if [ ! -d "$Directory_To" ];then
fi
for picture in $Pictures
do
done
echo -e " "
echo -e "Converting e[32;1msucessfully!e[0m"
exit 0
################################################
交互式脚本1:
#!/bin/bash
echo -e "请按下列格式输入图片所在\033[31;1m目录\e[0m \e[32;1m源格式\033[0m \e[33;1m目标格式\e[0m \e[34;1m分辨率\e[0m \e[35;1m色彩深度\e[0m"
echo ""
echo "/home/test png xpm 640x480 16"
echo ""
read -p "You input:" input
dir=$(echo $input|gawk '{print $1}')
sf=$(echo $input|gawk '{print $2}')
of=$(echo $input|gawk '{print $3}')
ge=$(echo $input|gawk '{print $4}')
co=$(echo $input|gawk '{print $5}')
echo "Please wait a moment"
cd $dir
for i in $(ls *.$sf)
echo "Done"
交互式脚本2:
#!/bin/bash
read -p "Directory:" dir
read -p "source format:(png or bmp ...)" sf
read -p "object format:(xpm or ...)" of
read -p "geometry:(800x600...)" go
read -p "colors:(16 ...)" co
for i in $(ls *.$sf $dir)
echo "Done"
以下是官方提供的实现方式,供参考之用
# Use find to substitute filenames into a 'convert' command.
# This also provides the ability to recurse though directories by removing
# the -prune option, as well as doing other file checks (like image type,
# or the disk space used by an image).
find * -prune -name '*.jpg' -exec convert '{}' -thumbnail 200x90 thumbnails/'{}'.gif ;
# Use xargs -- with a shell wrapper to put the argument into a variable
# This can be combined with either "find" or "ls" to list filenames.
ls *.jpg | xargs -n1 sh -c 'convert $0 -thumbnail 200x90 thumbnails/$0.gif'
# An alternative method on linux (rather than plain unix)
# This does not need a shell to handle the argument.
ls *.jpg | xargs -r -I FILE convert FILE -thumbnail 200x90 FILE_thumb.gif
2.修改图像的尺寸
convert
convert
3.图像旋转
convert
convert
convert
-draw
convert
在图像的10,80 位置采用60磅的全黑Helvetica字体写上 Hello, World!
至于高阶用法,如:裁剪、淡化、抖动、炭化、加边框、圆角等等一系列操作,可以参考官方帮助文档