A Rails image_tag() extension to generate HTML5
The following image_tag
= image_tag 'awesome/picture.jpeg', alt: 'awesome', responsive: truewill generate this output:
<picture>
<source media="(max-width: 767px)" srcset="/assets/responsive_images_767/picture.jpg">
<source media="(max-width: 991px)" srcset="/assets/responsive_images_991/picture.jpg">
<source media="(max-width: 1999px)" srcset="/assets/responsive_images_1999/picture.jpg">
<img width="2568" height="878" alt="awesome" src="/assets/picture.jpg">
</picture>Add this line to your application's Gemfile:
gem 'rails_responsive_images'And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_responsive_images
Configure the size steps you want to create:
RailsResponsiveImages.configure do |c|
c.image_sizes = [767, 991, 1999]
endRequire jquery-picture for cross browser support
//= require jquery-pictureAdd the responsive flag on image_tag helper
= image_tag 'awesome/picture.jpeg', alt: 'awesome', responsive: truebefore 'deploy:assets:precompile', 'build_responsive_images'
task :build_responsive_images, roles: :app do
run "cd #{release_path} && RAILS_ENV=#{rails_env} bundle exec rake rails_responsive_images"
endhttps://github.com/chilian/rails_responsive_images/issues
- Fork it ( https://github.com/chilian/rails_responsive_images/fork )
- 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 a new Pull Request
Copyright © 2015 Christoph Chilian. See LICENSE.txt for further details.