批量创建缩略图

平时在创建缩略图时,经常用到 ImageMagick 中的 convert 程序。不过,仅限于创建单张图片的缩略图。今天,读到 CLI tricks: Creating image thumbnails 一文时,其中一段可以批量创建图片缩略图的代码相当受用,兹录于后。 for file in *.png do convert -resize 200 "$file" thumb_"$file" done

这段代码将对目录中的所有 png 文件生成对应宽度为 200px 的缩略图。如果需要对其他图像文件格式进行操作,那么可以修改代码中的 png。与此同时,对于最终生成缩略图的大小也可根据自己需要进行修改。

如何使用这段代码呢?相当简单,创建个新的文件,粘贴上这段代码,然后在文件之前加上 #!/bin/bash。保存后,chmod +x 该文件即可。

完整的代码可从这里看到。

Read More:

  • No related posts

4 Comments

  1. 1 coocend Commented @ 2006-10-28 13:37Reply to this comment

    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

  2. 2 Toy Commented @ 2006-10-28 15:06Reply to this comment

    太好了,这个增强版将更加好用。非常感谢 coocend 朋友。

  3. 3 alex Commented @ 2006-11-11 15:38Reply to this comment

    ATTENTION :  it will overwrite the original ones!

  4. 4 alex Commented @ 2006-11-11 15:54Reply to this comment

    sorry, iused it not properly. so ,go ahead. it is really a wonderful way to create thumbnails. thanks,toy and coocend