Skip to content

Instantly share code, notes, and snippets.

@colorbox
Last active June 20, 2018 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colorbox/8951c33e3f635a4b25fd4dc393e169e6 to your computer and use it in GitHub Desktop.
Save colorbox/8951c33e3f635a4b25fd4dc393e169e6 to your computer and use it in GitHub Desktop.
require 'RMagick'
require 'rubygems'
def crop_icons(filename)
original = Magick::Image.read(filename).first
prefix = File.basename(filename, ".*")
image = original.crop(356, 15, 53, 60)
image.write("icons/#{prefix}-1.jpg")
image = original.crop(356 + 53 + 5, 15, 53, 60)
image.write("icons/#{prefix}-2.jpg")
image = original.crop(356 + (53 + 5) * 2, 15, 53, 60)
image.write("icons/#{prefix}-3.jpg")
image = original.crop(356 + (53 + 5) * 3 - 1, 15, 53, 60)
image.write("icons/#{prefix}-4.jpg")
image = original.crop(356 + (53 + 5) * 3 + 167, 15, 53, 60)
image.write("icons/#{prefix}-5.jpg")
image = original.crop(356 + (53 + 5) * (3+1) + 167, 15, 53, 60)
image.write("icons/#{prefix}-6.jpg")
image = original.crop(356 + (53 + 5) * (3+2) + 167, 15, 53, 60)
image.write("icons/#{prefix}-7.jpg")
image = original.crop(356 + (53 + 5) * (3+3) + 167 - 1, 15, 53, 60)
image.write("icons/#{prefix}-8.jpg")
end
Dir.entries("./douga").each do |filename|
next unless File.extname(filename)==".jpg"
puts "./douga/#{filename}"
crop_icons("./douga/#{filename}")
end
# crop_icons('ika_image.jpg')
# original = Magick::Image.read('ika_image.jpg').first
#
# image = original.crop(356, 15, 53, 60)
# image.write('icons/1.jpg')
#
# image = original.crop(356 + 53 + 5, 15, 53, 60)
# image.write('icons/2.jpg')
#
# image = original.crop(356 + (53 + 5) * 2, 15, 53, 60)
# image.write('icons/3.jpg')
#
# image = original.crop(356 + (53 + 5) * 3 - 1, 15, 53, 60)
# image.write('icons/4.jpg')
#
# image = original.crop(356 + (53 + 5) * 3 + 167, 15, 53, 60)
# image.write('icons/5.jpg')
#
# image = original.crop(356 + (53 + 5) * (3+1) + 167, 15, 53, 60)
# image.write('icons/6.jpg')
#
# image = original.crop(356 + (53 + 5) * (3+2) + 167, 15, 53, 60)
# image.write('icons/7.jpg')
#
# image = original.crop(356 + (53 + 5) * (3+3) + 167 - 1, 15, 53, 60)
# image.write('icons/8.jpg')
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment