Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Avatar Resizer (See related posts)

I go on a lot of Bulletin Board, every has its own limits of size for the avatars, instead of the resize manually I created a script which does it for me with RMagick

#!/usr/bin/ruby
require "RMagick"
$SIZES = [80 , 100 , 110 , 128]

if !ARGV[0]
  puts "Usage: mk_avatars.rb SourceAvatarPath"
  exit
end

image = Magick::Image.read(ARGV[0]).first
$SIZES.each do |sz|
  puts "Generating Avatar : #{sz}"
  out = image.thumbnail(sz,sz)
  file = "out_#{sz}.#{image.format}"
  out.write(file)
end

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts