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.
Dimensions
To change the default image dimensions or add new ones you need to create a decorator file:
with the following content:
Using image variations in templates
You can also create image variations on the fly in your templates, eg.
Storage service
By default Spree will use the storage service you have set in your environment file eg. config/environments/development.rb
:
If you have multiple storage services you can customize which storage service to use for images. This is done in the config/initializers/spree.rb
:
The storage name needs to match the name you configured in config/storage.yml
.
Using CDNs
To use a CDN service such as AWS Cloudfront or Cloudflare, you need to set Spree.cdn_host
to the hostname of your CDN service. This is done in the config/initializers/spree.rb
:
Spree will handle the rest as we have a built-in reverse proxy for ActiveStorage.
To use CDN in your templates please use cdn_image_url
helper:
Was this page helpful?