Images

Overview

This guide explains how to change Product Images dimensions and different storage options for ActiveStorage which is the default attachment storage system in Spree.

Image dimensions

To change the default image dimensions or add new ones you need to create a decorator file app/models/my_store/spree/image_decorator.rb:
1
module MyStore
2
module Spree
3
module ImageDecorator
4
module ClassMethods
5
def styles
6
{
7
mini: '48x48>',
8
small: '100x100>',
9
product: '240x240>',
10
large: '600x600>',
11
}
12
end
13
end
14
​
15
def self.prepended(base)
16
base.inheritance_column = nil
17
base.singleton_class.prepend ClassMethods
18
end
19
end
20
end
21
end
22
​
23
::Spree::Image.prepend ::MyStore::Spree::ImageDecorator
Copied!
You can also create image variations on the fly in your templates, eg.
1
<%= image_tag(main_app.url_for(@product.images.first.attachment.variant(resize: '150x150'))) %>
Copied!

Using Amazon S3 as storage system

Please refer to the official Active Storage documentation​
Last modified 3mo ago