has-imgix-attachment allows you to easier work with the imgix API through model defined attributes for easier retrieval.
Add this line to your application's Gemfile:
gem 'has-imgix-attachment'
And then execute:
$ bundle
To add imgix to your model, you simply need to call the has-imgix-attachment
method on your model.
class Post < ActiveRecord::Base
has_imgix_attachment :photo,
:subdomain => "imgix-subdomain",
:default => "default.png",
:prefix => "photos",
:styles => {
:thumbnail => {
:h => 90,
:w => 110,
:fit => "crop"
},
:large => {
:h => 480,
:w => 640,
:fit => "crop"
}
}
end
The has-imgix-attachment
method will take accept a name, and a list of options. The first value is the name and of the field that we'll create (which can also be referenced with imgix_attachment
). Below is a list of valid options that can follow the name.
subdomain
- Subdomain defined within your imgix accountdefault
- Name of the image to be used as a default image (must appear in the bucket with all other images)prefix
- If your bucket has folders, supply the folder name herefilename_field
- Override the default column name for the image filename. Default: filenamefile_size_field
- Override the default column name for the image file size. Default: file_sizecontent_type_field
- Override the default column name for the image content type. Default: content_typestyles
- Hash that defines all the variations of the image you'd like to be able to refer to
NOTE: Examples of the model configurations can be found in the spec/support/models.rb
file.
The gem comes with a view helper imgix_tag
which is just an extension of the image_tag
.
<%= imgix_tag(@post.photo, "large") %>
will generate the same thing as, just a less verbose shortcut
<%= imgix_tag(@post.imgix_attachment, "large") %>
imgix_tag will accept all the same additional options that image_tag supports
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
)- Please make sure to include the appropriate specs
- Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
See LICENSE.txt.