Skip to content

Instantly share code, notes, and snippets.

@tokenvolt
Created July 26, 2013 23:05
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 tokenvolt/6092836 to your computer and use it in GitHub Desktop.
Save tokenvolt/6092836 to your computer and use it in GitHub Desktop.
Default images for carrierwave using placeholder.it
class DefaultImage
def initialize(width, height)
@width = width
@height = height
end
def create(options={})
name = options[:name] || "image_#{Time.now.to_i}"
default_format = 'png'
format = options[:format] || default_format
url = 'http://placehold.it/' + @width.to_s + 'x' + @height.to_s
image = MiniMagick::Image.open(url)
image.format format
path = "#{Rails.root}/app/assets/images/fallback/" + [name, format].join('.')
image.write path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment