https://github.com/rafaelcaricio/thumbor_rails
DESCRIPTION
thumbor_rails is a client to make easier to use the thumbor imaging service (http://github.com/globocom/thumbor) in Ruby and Rails projects.
Installation
You can use this gem by putting the following inside your Gemfile:
gem "thumbor_rails", "1.2.0"
Now generate the thumbor basic client configuration:
rails g thumbor_rails:install
It will generate the basic configuration in config/initializers/thumbor_rails.rb, which has the following configuration options available:
-
server_url. Required. The location of your Thumbor server. Ifserver_urlcontains%d, it will be interpolated to 0-3, just likeasset_hostfor Rails. -
sercurity_key. Optional. This must match your Thumbor server's security key. -
force_no_protocol_in_source_url. Optional, defaults tofalse. If true, the protocol is removed from any image source passed intothumbor_url. This may be done for aesthetic reasons, or due to certain CDN/server configurations.
Usage
There are two basic helpers you can use in your views:
thumbor_url
thumbor_image_tag
thumbor_url
The thumbor_url helper allows you to to generate a thumbor url, a simple use is:
<%= thumbor_url "http://example.com/awesome_image.jpg" %>Of course, you can pass various parameters to thumbor as described in the ruby-thumbor gem. An exemple would be:
<%= thumbor_url "http://example.com/awesome_image.jpg", width: 200, height: 300 %>thumbor_image_tag
The thumbor_image_tag helper allows you to simplify the usage when creating a simple image tag in your views. It returns a complete image tag with the generated thumbor url in the src attribute of the img tag. Example:
<%= thumbor_image_tag "http://myimage.jpg", unsafe: true, width: 100, height: 100 %>Will result in something like:
<img alt="Myimage" src="http://thumbor.example.com/unsafe/100x100/http://myimage.jpg" />Disabling Thumbor
Setting the DISABLE_THUMBOR environment variable will disable thumbor_image_tag and thumbor_url and they will return the original url instead. This is in case you don't want to use Thumbor locally or want to disable it temporarily.
Maintainers
- Rafael Caricio (@rafaelcaricio)
and contributors.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Extras
If you do not have yet an instance of thumbor for you. You can get one for free up and running in the OpenShift Cloud.