Compare commits

...

9 Commits

Author SHA1 Message Date
Joseph Wynn
296ff67a48 Merge pull request #55 from wildlyinaccurate/jameswood-exif-rotate
Rotate resized images based on EXIF data
2017-03-13 08:45:27 +00:00
Joseph Wynn
80eca76d57 Fix auto_rotate name in Jekyll::ResponsiveImage::Config#DEFAULTS 2017-03-13 08:41:37 +00:00
Joseph Wynn
344b21142b Merge pull request #56 from wildlyinaccurate/update-dependencies
Update dependencies and run tests on latest Rubies
2017-03-12 15:05:06 +00:00
Joseph Wynn
37a267c3ac Update dependencies and run tests on latest Rubies 2017-03-12 14:59:25 +00:00
Joseph Wynn
b611cf424d Minor version bump for new functionality 2017-03-12 14:16:20 +00:00
Joseph Wynn
56181bc4c9 Write tests for auto_rotate option 2017-03-12 14:14:53 +00:00
Joseph Wynn
1cf136091a Rename auto rotate option to auto_rotate 2017-03-12 14:14:45 +00:00
jameswood
438bb264d1 rotate resized images based on exif info
EXIF rotation information embedded by the capture device is now
respected when generating output images. Original images remain
untouched.
2017-03-10 16:03:03 +11:00
Joseph Wynn
0cc608031e Set the linguist-vendored attribute on features/test-site/*
This prevents Linguist from including the directory in the GitHub language stats
2017-01-09 11:37:19 +13:00
9 changed files with 64 additions and 8 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
features/test-site/* linguist-vendored

View File

@ -1,9 +1,12 @@
sudo: false
dist: trusty
language: ruby
bundler_args: --without debug
before_script: bundle exec jekyll --version
script: bundle exec rake features_with_coveralls
rvm:
- 2.2
- 2.1
- 2.0
- '2.4'
- '2.3'
- '2.2'
- '2.1'
- '2.0'

View File

@ -4,8 +4,8 @@ gemspec
group :development do
gem 'rake'
gem 'cucumber', '~> 2.1'
gem 'test-unit', '~> 3.1'
gem 'cucumber', '~> 2.4'
gem 'test-unit', '~> 3.2'
gem 'simplecov', :require => false
gem 'coveralls', :require => false

View File

@ -47,6 +47,11 @@ responsive_image:
- width: 1400
quality: 90
# [Optional, Default: false]
# Rotate resized images depending on their EXIF rotation attribute. Useful for
# working with JPGs directly from digital cameras and smartphones
auto_rotate: false
# [Optional, Default: assets]
# The base directory where assets are stored. This is used to determine the
# `dirname` value in `output_path_format` below.
@ -128,7 +133,23 @@ You will need to create a template in order to use the `responsive_image` tag. B
{% endfor %}
{% endcapture %}
<img src="/{{ path }}" alt="{{ alt }}" srcset="{{ srcset | strip_newlines }} /{{ original.path }} {{ original.width }}w">
<img src="/{{ path }}" alt="{{ alt }}" srcset="{{ srcset | strip_newlines }}">
```
#### Responsive image with `srcset` where the largest resized image is the default
> **Note:** This is useful if you don't want your originals to appear on your site. For example, if you're uploading full-res images directly from a device.
```twig
{% capture srcset %}
{% for i in resized %}
/{{ i.path }} {{ i.width }}w,
{% endfor %}
{% endcapture %}
{% assign largest = resized | sort: 'width' | last %}
<img src="/{{ largest.path }}" alt="{{ alt }}" srcset="{{ srcset | strip_newlines }}">
```
#### Responsive images with `<picture>`

View File

@ -62,3 +62,31 @@ Feature: Responsive image generation
When I run Jekyll
Then the image "my-site-copy/src/assets/resized/subdir/100/test.png" should have the dimensions "100x50"
And the file "_site/assets/resized/subdir/100/test.png" should exist
Scenario: Images can be auto-rotated based on EXIF rotation
Given I have a responsive_image configuration with:
"""
template: _includes/responsive-image.html
sizes:
- width: 100
auto_rotate: true
"""
And I have a file "index.html" with "{% responsive_image path: assets/exif-rotation.jpeg %}"
When I run Jekyll
Then the file "_site/assets/resized/exif-rotation-100x200.jpeg" should exist
Scenario: Images aren't auto-rotated by default
Given I have a responsive_image configuration with:
"""
template: _includes/responsive-image.html
sizes:
- width: 100
"""
And I have a file "index.html" with:
"""
{% responsive_image path: assets/exif-rotation.jpeg %}
{% responsive_image path: assets/progressive.jpeg %}
"""
When I run Jekyll
Then the file "_site/assets/resized/exif-rotation-100x50.jpeg" should exist
Then the file "_site/assets/resized/progressive-100x50.jpeg" should exist

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -6,7 +6,8 @@ module Jekyll
'base_path' => 'assets',
'output_path_format' => 'assets/resized/%{filename}-%{width}x%{height}.%{extension}',
'sizes' => [],
'extra_images' => []
'extra_images' => [],
'auto_rotate' => false
}
def initialize(site)

View File

@ -4,6 +4,8 @@ module Jekyll
include ResponsiveImage::Utils
def resize_image(img, config)
img.auto_orient! if config['auto_rotate']
resized = []
config['sizes'].each do |size|

View File

@ -1,5 +1,5 @@
module Jekyll
module ResponsiveImage
VERSION = '1.1.0'.freeze
VERSION = '1.2.0'.freeze
end
end