Created
May 23, 2012 07:30
-
-
Save gangmax/2773708 to your computer and use it in GitHub Desktop.
The is an example to use ruby control command line tool(ImageMagick) to deal with image processing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# | |
# This program is used to convert all the png files under the given path, | |
# from colorful to grey, from big to small(70% as original), from png to | |
# gif, and then keep the file name unchanged(still *.png). | |
# | |
# Running this program needs you have "imagemagick" installed. | |
# | |
require 'find' | |
unless ARGV.length == 1 | |
puts "Usage: image_converter.rb /home/user/images" | |
exit | |
end | |
Find.find(ARGV[0]) do |f| | |
if f.end_with?('.png') | |
bw_name = f + '.bw.png' | |
bw_gif_name = bw_name + '.gif' | |
`convert -colorspace GRAY '#{f}' '#{bw_name}'` | |
`rm '#{f}'` | |
`convert '#{bw_name}' -resize 70% '#{bw_gif_name}'` | |
`rm '#{bw_name}'` | |
`mv '#{bw_gif_name}' '#{f}'` | |
puts "convert '#{f}' ok." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment