An unopinionated Jekyll plugin for generating and using responsive images https://github.com/wildlyinaccurate/jekyll-responsive-image
Go to file
Joseph Wynn 4b0c8c390f Ignore generated gemfiles 2014-12-06 19:16:18 +00:00
features Enable Coveralls 2014-12-06 16:03:10 +00:00
lib/jekyll 0.9.1 2014-12-06 16:07:12 +00:00
.coveralls.yml Add Coveralls 2014-12-06 00:04:33 +00:00
.gitignore Ignore generated gemfiles 2014-12-06 19:16:18 +00:00
.travis.yml Add Coveralls 2014-12-06 00:04:33 +00:00
Gemfile Add Coveralls 2014-12-06 00:04:33 +00:00
LICENSE Add LICENSE and README 2014-12-06 00:30:55 +00:00
README.md Update documentation 2014-12-06 15:43:15 +00:00
Rakefile Ensure tags are annotated 2014-12-06 01:13:16 +00:00
index.html Initial commit 2014-12-05 16:26:50 +00:00
jekyll-responsive_image.gemspec Rename gem to jekyll-responsive_image 2014-12-06 01:01:15 +00:00
test-index.html Initial commit 2014-12-05 16:26:50 +00:00

README.md

Jekyll Responsive Images

Jekyll Responsive Images is a Jekyll plugin and utility for automatically resizing images. Its intended use is for sites which want to display responsive images using something like srcset or Imager.js.

Build Status Coverage Status Dependency Status

Installation

You can either use the gem and update your _config.yml:

$ gem install jekyll-responsive_image
# _config.yml
gems: [jekyll-responsive_image]

Or you can simply copy responsive_image.rb into your _plugins directory.

Configuration

An example configuration is below.

responsive_image:
  template: '_includes/responsive-image.html' # Path to the template to render. Required.

  # An array of resize configurations. When this array is empty (or not specified),
  # no resizing will take place.
  sizes:
    - width: 480 # How wide the resized image will be. Required
    - width: 800
      quality: 90 # Override JPEG quality (default is 85). Optional.
    - width: 1400

Usage

Replace your images with the responsive_image tag, specifying the path to the image in the path attribute.

{% responsive_image path: assets/my-file.jpg %}

You can override the template on a per-image basis by specifying the template attribute.

{% responsive_image path: assets/my-file.jpg template: _includes/another-template.html %}

Any extra attributes will be passed straight to the template as variables.

{% responsive_image path: assets/image.jpg alt: "Lorem ipsum..." title: "Lorem ipsum..." %}

Template

You will need to create a template in order to use the responsive_image tag. A sample template is below.

<img src="/{{ path }}"
     alt="{{ alt }}"
     title="{{ title }}"

     {% if resized %}
         srcset="{% for i in resized %}
             /{{ i.path }} {{ i.width }}w{% if forloop.last == false %},{% endif %}
         {% endfor %}"
     {% endif %}
>

Template Variables

The following variables are available in the template:

Variable Type Description
path String The path of the unmodified image. This is always the same as the path attribute passed to the tag.
resized Array An array of all the resized images. Each image contains the properties listed below.
* String Any other attributes will be passed to the template verbatim as strings.

Each element in the resized array contains the following properties:

Variable Type Description
path String The path of the resized image.
width Integer The width of the resized image.
height Integer The height of the resized image.