Merge pull request #68 from driehuis/master

Add option to strip EXIF profiles
This commit is contained in:
Joseph Wynn 2018-01-23 15:05:17 +13:00 committed by GitHub
commit b628a11925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 1 deletions

View File

@ -52,6 +52,11 @@ responsive_image:
# working with JPGs directly from digital cameras and smartphones
auto_rotate: false
# [Optional, Default: false]
# Strip EXIF and other JPEG profiles. Helps to minimize JPEG size and win friends
# at Google PageSpeed.
strip: false
# [Optional, Default: assets]
# The base directory where assets are stored. This is used to determine the
# `dirname` value in `output_path_format` below.

View File

@ -86,3 +86,34 @@ Feature: Responsive image generation
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
Scenario: Images should not be stripped of EXIF info 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 %}
"""
When I run Jekyll
Then the file "_site/assets/resized/exif-rotation-100x50.jpeg" should exist
Then the image "_site/assets/resized/exif-rotation-100x50.jpeg" should have an EXIF orientation
Scenario: Images can be stripped of EXIF info
Given I have a responsive_image configuration with:
"""
template: _includes/responsive-image.html
sizes:
- width: 100
strip: 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-100x50.jpeg" should exist
Then the image "_site/assets/resized/exif-rotation-100x50.jpeg" should have no EXIF orientation

View File

@ -65,6 +65,18 @@ Then /^the image "(.+)" should be interlaced$/ do |path|
img.destroy!
end
Then /^the image "(.+)" should have an EXIF orientation$/ do |path|
img = Magick::Image::read(path).first
assert_not_equal img.orientation.to_i, 0
img.destroy!
end
Then /^the image "(.+)" should have no EXIF orientation$/ do |path|
img = Magick::Image::read(path).first
assert_equal img.orientation.to_i, 0
img.destroy!
end
def write_file(path, contents)
File.open(path, 'w') do |f|
f.write(contents)

View File

@ -9,7 +9,8 @@ module Jekyll
'extra_images' => [],
'auto_rotate' => false,
'save_to_source' => true,
'cache' => false
'cache' => false,
'strip' => false
}
def initialize(site)

View File

@ -36,6 +36,9 @@ module Jekyll
Jekyll.logger.info "Generating #{target_filepath}"
if config['strip']
img.strip!
end
i = img.scale(ratio)
i.write(target_filepath) do |f|
f.interlace = i.interlace