LinuxTOY 是一个致力于提供 Linux 相关资讯的专题站点。如果您发现了好用好玩的 Linux 东东并愿意发扬自由、分享的精神,可以点击顶部导航 Contact 按钮进行投稿。
  • Laptops
  • make $500 extra a day!

Related entries

  • No related posts

Latest entries

批量创建缩略图

平时在创建缩略图时,经常用到 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 该文件即可。

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

4 Comments

  1. coocend 1 coocend Commented @ 2006-10-28 1:37 pm

    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. Toy 2 Toy Commented @ 2006-10-28 3:06 pm

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

  3. alex 3 alex Commented @ 2006-11-11 3:38 pm

    ATTENTION :  it will overwrite the original ones!

  4. alex 4 alex Commented @ 2006-11-11 3:54 pm

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