Cloudimage integration for Shrine.
Supports Ruby 2.4 and above, JRuby, and TruffleRuby.
Add this line to your application's Gemfile:
gem 'shrine-cloudimage'And then execute:
$ bundle install
Or install it yourself as:
$ gem install shrine-cloudimage
Register the plugin with any valid Cloudimage settings:
Shrine.plugin :cloudimage, client: {
token: 'token', salt: 'salt', sign_urls: false, signature_length: 10
}Or pass in the client object directly:
require 'cloudimage'
Shrine.plugin :cloudimage, client: Cloudimage::Client.new(
token: 'token', salt: 'salt', sign_urls: false, signature_length: 10
)See cloudimage for a list of available options.
You can generate a Cloudimage URL for a Shrine::UploadedFile object by
calling #cloudimage_url:
photo.image.cloudimage_url(w: 300, h: 300, blur: 5)
# => "https://token.cloudimg.io/v7/https://my-bucket.s3.us-east-1.amazonaws.com/assets/image.jpg?blur=5&h=300&w=300"Cloudimage client can also be accessed directly. This way you can centralize your config in Shrine initializer and reuse it across your codebase:
uri = Shrine.cloudimage_client.path('/assets/image.png')
uri.w(200).h(400).to_url
# => "https://token.cloudimg.io/v7/assets/image.png?h=400&w=200"Generate srcset for a Shrine::UploadedFile object by calling #cloudimage_srcset:
photo.image.cloudimage_srcset(blur: 5)
# => "https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=100 100w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=170 170w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=280 280w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=470 470w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=780 780w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=1300 1300w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=2170 2170w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=3620 3620w, https://token.cloudimg.io/v7/assets/image.jpg?blur=5&w=5760 5760w"Set :invalidate to true if you want images to be automatically
purged from Cloudimage on deletion:
Shrine.plugin :cloudimage, client: { token: 'token', api_key: 'key' }, invalidate: trueYou can also invalidate all cached transformations of the given image manually with
Shrine::UploadedFile#cloudimage_invalidate:
photo.image.cloudimage_invalidateNote that invalidation requires passing the :api_key option to your Cloudimage client.
After checking out the repo, run bundle install to install dependencies.
Then, run bundle exec rake to run the tests.
Bug reports and pull requests are welcome! This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.