Skip to content

janklimo/shrine-cloudimage

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Shrine::Plugins::Cloudimage

Gem Version Build status

Cloudimage integration for Shrine.

Supports Ruby 2.4 and above, JRuby, and TruffleRuby.

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

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages