From 826b5f715e96f11d4ba5c64d29af864148e4e34d Mon Sep 17 00:00:00 2001 From: Bert Driehuis Date: Fri, 19 Jan 2018 01:08:35 +0100 Subject: [PATCH 1/2] Add option to strip EXIF profiles --- README.md | 5 +++++ lib/jekyll-responsive-image/config.rb | 3 ++- lib/jekyll-responsive-image/resize_handler.rb | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07cc999..0741736 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/jekyll-responsive-image/config.rb b/lib/jekyll-responsive-image/config.rb index 7d4f368..3880abd 100644 --- a/lib/jekyll-responsive-image/config.rb +++ b/lib/jekyll-responsive-image/config.rb @@ -9,7 +9,8 @@ module Jekyll 'extra_images' => [], 'auto_rotate' => false, 'save_to_source' => true, - 'cache' => false + 'cache' => false, + 'strip' => false } def initialize(site) diff --git a/lib/jekyll-responsive-image/resize_handler.rb b/lib/jekyll-responsive-image/resize_handler.rb index bc86b68..9f9f5bc 100644 --- a/lib/jekyll-responsive-image/resize_handler.rb +++ b/lib/jekyll-responsive-image/resize_handler.rb @@ -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 From cafec3c926c146659ac18b6ba197f61d813c6913 Mon Sep 17 00:00:00 2001 From: Bert Driehuis Date: Fri, 19 Jan 2018 02:13:21 +0100 Subject: [PATCH 2/2] Add feature tests for EXIF strip --- features/image-generation.feature | 31 +++++++++++++++++++++++ features/step_definitions/jekyll_steps.rb | 12 +++++++++ 2 files changed, 43 insertions(+) diff --git a/features/image-generation.feature b/features/image-generation.feature index 57d7c00..2fdc1c2 100644 --- a/features/image-generation.feature +++ b/features/image-generation.feature @@ -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 diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index f89fc72..0780605 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -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)