LoginSignup
6
7

More than 5 years have passed since last update.

画像をまとめてリサイズするスクリプト

Last updated at Posted at 2015-05-09

画像を一括でリサイズします。リサイズした画像はthums/フォルダ以下に格納されます。chmod +xしてパスの通った場所におくと便利です。

使い方

$ resize 50% a.png b.png
convert -resize 50% a.png ./thums/a.png
convert -resize 50% b.png ./thums/b.png

$ resize 320x480 a.jpg b.jpg

ソースコード

mytool/resize

#!/usr/bin/env ruby
# Resize images  using the ImageMagick
#
#   $ resize 50% a.png b.png
#   convert -resize 50% a.png ./thums/a.png
#   convert -resize 50% b.png ./thums/b.png

require 'fileutils'
require 'rake'

size = ARGV.shift

ARGV.each do |path|
  dst_dir = "#{File.dirname(path)}/thums"
  FileUtils.mkdir_p dst_dir

  dst = "#{dst_dir}/#{File.basename(path)}"

  sh "convert -resize #{size} #{path} #{dst}"
end
6
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7