Skip to content

Instantly share code, notes, and snippets.

@kurko
Created July 26, 2011 18:23
Show Gist options
  • Save kurko/1107437 to your computer and use it in GitHub Desktop.
Save kurko/1107437 to your computer and use it in GitHub Desktop.
Small script for resizing and saving (caching) images inside a directory
require 'mini_magick'
suffix = "cached_"
sleep_between_process = 0.3
sizes = ["x142","x200"]
# loop through files
Dir.glob("[^cache]*").each { |e|
image_path = File.expand_path(e)
image = MiniMagick::Image.open(image_path)
sizes.each { |size|
image.resize(size)
image.write suffix+size+"_"+e
sleep(sleep_between_process)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment