Skip to content

Instantly share code, notes, and snippets.

@cmaujean
Created September 5, 2011 19:46
Show Gist options
  • Save cmaujean/1195759 to your computer and use it in GitHub Desktop.
Save cmaujean/1195759 to your computer and use it in GitHub Desktop.
S3 for uploaded images, and automatic watermarking in Spree 0-60-stable
# app/models/image_decorator.rb
Image.class_eval do
has_attached_file(
:attachment,
:storage => :s3,
:bucket => ENV['S3_BUCKET']
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
},
:processors => [:thumbnail, :watermark],
:styles => {
:mini => {
:geometry => '48x48>',
:watermark_path => "#{Rails.root.to_s}/public/images/watermarks/tiny.png",
:watermark_position => "SouthWest",
:format => :png,
},
:small => {
:geometry => '100x100>',
:watermark_path => "#{Rails.root.to_s}/public/images/watermarks/small.png",
:watermark_position => "SouthWest",
:format => :png,
},
:product => {
:geometry => '240x240>',
:watermark_path => "#{Rails.root.to_s}/public/images/watermarks/product.png",
:watermark_position => "SouthWest",
:format => :png,
},
:large => {
:geometry => '600x600>',
:watermark_path => "#{Rails.root.to_s}/public/images/watermarks/large.png",
:watermark_position => "SouthWest",
:format => :png,
},
},
:default_style => :product,
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment