No release in over 3 years
Low commit activity in last 3 years
Fast and easy image resizing, transformation, and acceleration in the Cloud.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 2.0, < 4
 Project Readme

Shrine::Plugins::Cloudimage

Gem Version Build status

Cloudimage integration for Shrine.

Supports Ruby 2.4 and above, JRuby, and TruffleRuby.

  • Shrine::Plugins::Cloudimage
    • Installation
    • Configuration
    • Usage
      • srcset generation
      • Invalidation API
    • Development
    • Contributing
    • License

Installation

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

Configuration

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.

Usage

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"

srcset generation

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"

Invalidation API

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: true

You can also invalidate all cached transformations of the given image manually with Shrine::UploadedFile#cloudimage_invalidate:

photo.image.cloudimage_invalidate

Note that invalidation requires passing the :api_key option to your Cloudimage client.

Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rake to run the tests.

Contributing

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.

License

MIT