图片批处理

Posted 10 months ago at 11:30 am. 0 comments

ad 468x60

循环所有jpg图片,转换为 70×100 大小并该名为 _thumb.xxxx 的形式。filebrowser 手工 thumbnailer 太慢了…

for img in `ls *.jpg`; do convert -resize 70×100 ${img} _thumb.${img}; done

批处理目录

for dir in `ls`; do cd ${dir};ls; for img in `ls *.jpg`; do convert -resize 70×100 ${img} _thumb.${img}; done; cd ..; done

for d in `ls`;do cd ${d};for dir in `ls`; do cd ${dir};ls; for img in `ls *.jpg`; do convert -resize 70×100 ${img} _thumb.${img}; done; cd ..; done;cd ..;done;

2006-11-01+今天看到这个

for file in *.png
do
convert -resize 200 “$file” thumb_”$file”
done

he above script will create thumbs of width 200px for all the PNG images located in the current folder. What if you have JPEG images instead of PNGs? Well, you can just replace the extension in the loop with the one you like, since ImageMagick works with all common image formats.

Another option for such task is to use the mogrify script that comes with ImageMagick as well. A sample usage could look like this:

mogrify -resize 200 *.png

The important difference is that mogrify overwrites the original image file, whereas, convert writes to a different image file. Thanks for memals for pointing this out.

更多参考:

http://polishlinux.org/apps/cli-tricks-creating-image-thumbnails/
http://www.imagemagick.org/script/convert.php

shell script可以接受命令行参数,稍微修改下将更方便。
下面这个可以指定一个类型进行转换,默认转换全部jpg bmp gif? ?式的
ps:看livid的blog来这里的,界面很舒服,喜欢。
————-
#!/bin/bash
if [ $# -lt 1 ]
then
for ext in jpg bmp gif
do
for file in *.$ext
do
if [ -r $file ]
then
convert -resize 200 “$file” thumb_”$file”
fi
done
done
else
for file in *.$1
do
if [ -r $file ]
then
convert -resize 200 “$file” thumb_”$file”
fi
done
fi

相关日志:
linux 批处理学习笔记

Popularity: 6% [?]

Tags: , , , , , ,
ad 468x60

No Replies

Feel free to leave a reply using the form below!


Leave a Reply