Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Gem Version Build status

cloudimage is the official Ruby API wrapper for Cloudimage's API.

Supports Ruby 2.4 and above, JRuby, and TruffleRuby.


Add this line to your application's Gemfile:

gem 'cloudimage'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install cloudimage


The most common way to use Cloudimage is by means of your customer token. You can find it within your Admin interface:


In order to interact with Cloudimage, we'll first initialize a client service object:

client = 'mysecrettoken')

Cloudimage client accepts the following options:

Option Type Additional info
token string Required if cname is missing.
cname string Required if token is missing. See CNAME.
salt string Optional. See Security.
signature_length integer Optional. Integer value in the range 6..40. Defaults to 18.
sign_urls boolean Optional. Defaults to true. See Security.
aliases hash Optional. See URL aliases.
api_key string Optional. See Invalidation API.
include_api_version boolean Optional. Defaults to true. See Optional API version.

Calling path on the client object returns an instance of Cloudimage::URI. It accepts path to the image as a string and we we will use it to build Cloudimage URLs.

uri = client.path('/assets/image.png')

Here are some common approaches for constructing Cloudimage URLs using this gem:

Hash of params

Pass a hash to to_url. Every key becomes a param in the final Cloudimage URL so this gives you the freedom to pass arbitrary params if need be.

uri.to_url(w: 200, h: 400, sharp: 1, gravity: 'west', ci_info: 1)
# => ""

Chainable helpers

Every param supported by Cloudimage can be used as a helper method.

# => ""

While every key passed into to_url method gets appended to the URL, chainable helper methods will throw a NoMethodError when using an unsupported method.

# NoMethodError (undefined method `heigth' for #<Cloudimage::URI:0x00007fae461c42a0>)

This is useful for catching typos and identifying deprecated methods in case Cloudimage's API changes.

Method aliases

The gem comes with a handful of useful aliases. Consult Cloudimage::Params module for their full list.

# => ""

From the example above you can see that params that only serve as a flag don't need to accept arguments and will be translated into param=1 in the final URL.

Custom helpers

For a list of custom helpers available to you, please consult Cloudimage::CustomHelpers module.

URL aliases

Specify aliases to automatically replace parts of path with defined values. Aliases is a hash which maps strings to be replaced with values to be used instead.

my_alias = ''
client = 'token', aliases: { my_alias => '_uploads_' })
# => ""

URL prefix is just another form of URL alias. Simply make the target value an empty string:

prefix = ''
client = 'token', aliases: { prefix => '' })
# => ""

You don't need to specify an alias if the input to path is a URL that already matches the base of the generated URL:

client = 'token')
client.path('').to_url(w: 200)
=> ""

srcset generation

Use the provided to_srcset method which also accepts any additional params to be applied to the srcset URLs:

client = 'token')
client.path('/assets/image.jpg').to_srcset(blur: 5)
# => " 100w, 170w, 280w, 470w, 780w, 1300w, 2170w, 3620w, 5760w"

A growth factor is applied to exponentially distribute widths between 100 and 5760 pixels. See Cloudimage::Srcset for implementation details.


If you have a custom CNAME configured for your account, you can use it to initialize the client:

client = '')
# => ''

Optional API version

If your account is configured to work without the API version component in the URL, you can configure client not to include it in the generated URL:

client = '', include_api_version: false)
# => ""


URL signature

If salt is defined, all URLs will be signed.

You can control the length of the generated signature by specifying signature_length when initializing the client.

client = 'mysecrettoken', salt: 'mysecretsalt', signature_length: 10)
uri = client.path('/assets/image.png')
# => ""

URL sealing

Whereas URL signatures let you protect your URL from any kind of tampering, URL sealing protects the params you specify while making it possible to append additional params on the fly.

This is useful when working with Cloudimage's responsive frontend libraries. A common use case would be sealing your watermark but letting the React client request the best possible width.

To seal your URLs, initialize client with salt and set sign_urls to false. signature_length setting is applied to control the length of the generated ci_seal value.

Use the seal_params helper to specify which params to seal as a list of arguments. These could be symbols or strings.

client = 'demoseal', salt: 'test', sign_urls: false)

  .seal_params(:w, :f)
# => ""

# Alternative approach:
  .to_url(f: 'bright:10,contrast:20', w: 300, h: 400, seal_params: [:w, :f])
# => ""

This approach protects w and f values from being edited but makes it possible to freely modify the value of h.

Invalidation API

To access invalidation API you'll need to initialize client with an API key.

The provided helper methods accept any number of strings:

client = 'token', api_key: 'key')

# Invalidate original

# Invalidate URLs
client.invalidate_urls('/v7/image.jpg?w=200', '/v7/image.jpg?h=300')

# Invalidate all

Consult the invalidation API docs for further details.


After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.


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.




Among others, cloudimage is used to power the following apps:

  • Robin PRO - Fast, beautiful, mobile-friendly image galleries for Shopify stores.
  • Spotlightify - Turning the spotlight on the best Shopify stores.

Using this gem in your app? Let us know in this issue so that we can feature it.


Official Ruby API wrapper for Cloudimage's API. Any questions or issues, please report to



Code of conduct





No packages published