Skip to content

Instantly share code, notes, and snippets.

@ymek
Created August 24, 2012 19:08
Show Gist options
  • Select an option

  • Save ymek/3454492 to your computer and use it in GitHub Desktop.

Select an option

Save ymek/3454492 to your computer and use it in GitHub Desktop.
def thumbify
path = File.join(Rails.root, 'tmp', 'broken_art')
original_image = 'c11c42280223d6a199c0ffe069a2949ef07ff42a.jpg'
ImageScience.with_image(File.join(path, original_image)) do |image|
styles = {
thumb: { width: 75, height: 75, thumbnail: true, async: true },
small: { width: 150, height: 150, thumbnail: true, async: true },
medium: { width: 320, height: 320, thumbnail: true, async: true },
large: { width: 640, height: 640, thumbnail: true }
}
styles.each do |name, vals|
image.thumbnail(vals[:width]) do |thumb|
thumb.save(File.join(path, "#{original_image.sub(/\./, "_#{name}.")}"))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment