Skip to content

Commit

Permalink
Merge pull request #68 from driehuis/master
Browse files Browse the repository at this point in the history
Add option to strip EXIF profiles
  • Loading branch information
wildlyinaccurate authored Jan 23, 2018
2 parents c9da267 + cafec3c commit b628a11
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions features/image-generation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions features/step_definitions/jekyll_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
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)
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll-responsive-image/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Config
'extra_images' => [],
'auto_rotate' => false,
'save_to_source' => true,
'cache' => false
'cache' => false,
'strip' => false
}

def initialize(site)
Expand Down
3 changes: 3 additions & 0 deletions lib/jekyll-responsive-image/resize_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def resize_image(img, config)

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
Expand Down

0 comments on commit b628a11

Please sign in to comment.