Provides Imgix integration for Shrine.
Imgix is a service for processing images on the fly, and works with files stored on external services such as AWS S3 or Google Cloud Storage.
gem "shrine-imgix"
Load the imgix
plugin with Imgix client settings:
Shrine.plugin :imgix, client: {
host: "your-subdomain.imgix.net",
secure_url_token: "abc123",
}
You can also pass in an Imgix::Client
object directly:
require "imgix"
imgix_client = Imgix::Client.new(
host: "your-subdomain.imgix.net",
secure_url_token: "abc123",
)
Shrine.plugin :imgix, client: imgix_client
If you've configured a "Path Prefix" on your Imgix source, and you also have
:prefix
set on your Shrine storage, you'll need tell the imgix
plugin to
exclude the storage prefix from generated URLs:
Shrine.plugin :imgix, client: ..., prefix: false
You can generate an Imgix URL for a Shrine::UploadedFile
object by calling
#imgix_url
:
photo.image.imgix_url(w: 150, h: 200, fit: "crop")
#=> "http://my-subdomain.imgix.net/943kdfs0gkfg.jpg?w=150&h=200&fit=crop"
See the Imgix docs for all available URL options.
If you're using imgix-rails and want to use the ix_*
helpers, you can use
#imgix_id
to retrieve the Imgix path:
<%= ix_image_tag photo.image.imgix_id, url_params: { w: 300, h: 500, fit: "crop" } %>
If you want images to be automatically purged from Imgix on
deletion, you can set :purge
to true
:
Shrine.plugin :imgix, client: ..., purge: true
You can also purge manually with Shrine::UploadedFile#imgix_purge
:
photo.image.imgix_purge
Note that purging requires passing the :api_key
option to your Imgix client.
You can run the test suite with:
$ bundle exec rake test