jekyll-responsive-image 1.5.5 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89342834297499d845136be62d1749628efb0918712350daaa42250c30b3ceca
4
- data.tar.gz: caa5794d7b4e94d6ad29d6847a789a47afab054de1334a27659da8aaf3d04bd8
3
+ metadata.gz: 6997784f689936e81a50d386893ff4bab36054dcaa2811b3be30aecf5d02c6c8
4
+ data.tar.gz: 0133f99007cd590aed90e238feecdc822e94003168455285c1e4ea65340833c0
5
5
  SHA512:
6
- metadata.gz: 62c235deb0a949294656015a586afa3c75ab51e7699735e02d2b31293d40eff6224b6ec61c0ae380a24325e378efb278a59451f407dea53b91b70b958330c730
7
- data.tar.gz: 3b449dbe5259c80fa8a36d09746b3e48ef208f370b68e75367261c730a71aefb718fbf98622d8965a6ae32e31acf687de114c1a43dba003964e9fcab0ca906e9
6
+ metadata.gz: dab196e76bf72c37681e5ba3d0e87fb732c90fae7f58dc1e4db03a2bac0644345797412da9f854929a2d53b8881759e0b5cf8520a9d1c57bcaa34a2c2c6db4fe
7
+ data.tar.gz: f45b4fd482e8c75a728a3112ee4b0bbf3dc78f45c23f57bf9caeba2e830ae6d7ecba32a8634a3755545e6087a98555d01415c0b80f6f319473e2d9dc29a21a20
@@ -8,12 +8,11 @@ module Jekyll
8
8
 
9
9
  Jekyll.logger.warn "Invalid image path specified: #{image_path.inspect}" unless File.file?(absolute_image_path)
10
10
 
11
- resize_handler = ResizeHandler.new
12
- img = Magick::Image::read(absolute_image_path).first
11
+ resize_handler = ResizeHandler.new(absolute_image_path, config)
13
12
 
14
13
  {
15
- original: image_hash(config, image_path, img.columns, img.rows),
16
- resized: resize_handler.resize_image(img, config),
14
+ original: image_hash(config, image_path, resize_handler.original_image.columns, resize_handler.original_image.rows),
15
+ resized: resize_handler.resize_image,
17
16
  }
18
17
  end
19
18
 
@@ -25,7 +25,11 @@ module Jekyll
25
25
  partial = File.read(image_template)
26
26
  template = Liquid::Template.parse(partial)
27
27
 
28
- result = template.render!(@attributes.merge(@site.site_payload))
28
+ info = {
29
+ registers: { site: @site }
30
+ }
31
+
32
+ result = template.render!(@attributes.merge(@site.site_payload), info)
29
33
 
30
34
  RenderCache.set(cache_key, result)
31
35
  end
@@ -3,26 +3,39 @@ module Jekyll
3
3
  class ResizeHandler
4
4
  include ResponsiveImage::Utils
5
5
 
6
- def resize_image(img, config)
7
- img.auto_orient! if config['auto_rotate']
6
+ attr_reader :original_image
8
7
 
8
+ def initialize(original_image_absolute_path, config)
9
+ @config = config
10
+
11
+ @original_image_absolute_path = original_image_absolute_path
12
+
13
+ if @config['auto_rotate']
14
+ load_full_image
15
+ @original_image.auto_orient!
16
+ else
17
+ load_image_properties_only
18
+ end
19
+ end
20
+
21
+ def resize_image
9
22
  resized = []
10
23
 
11
- config['sizes'].each do |size|
24
+ @config['sizes'].each do |size|
12
25
  width = size['width']
13
- ratio = width.to_f / img.columns.to_f
14
- height = (img.rows.to_f * ratio).round
26
+ ratio = width.to_f / @original_image.columns.to_f
27
+ height = (@original_image.rows.to_f * ratio).round
15
28
 
16
- next unless needs_resizing?(img, width)
29
+ next unless needs_resizing?(width)
17
30
 
18
- image_path = img.filename.force_encoding(Encoding::UTF_8)
19
- filepath = format_output_path(config['output_path_format'], config, image_path, width, height)
20
- resized.push(image_hash(config, filepath, width, height))
31
+ image_path = @original_image.filename.force_encoding(Encoding::UTF_8)
32
+ filepath = format_output_path(@config['output_path_format'], @config, image_path, width, height)
33
+ resized.push(image_hash(@config, filepath, width, height))
21
34
 
22
- site_source_filepath = File.expand_path(filepath, config[:site_source])
23
- site_dest_filepath = File.expand_path(filepath, config[:site_dest])
35
+ site_source_filepath = File.expand_path(filepath, @config[:site_source])
36
+ site_dest_filepath = File.expand_path(filepath, @config[:site_dest])
24
37
 
25
- if config['save_to_source']
38
+ if @config['save_to_source']
26
39
  target_filepath = site_source_filepath
27
40
  else
28
41
  target_filepath = site_dest_filepath
@@ -36,16 +49,22 @@ module Jekyll
36
49
 
37
50
  Jekyll.logger.info "Generating #{target_filepath}"
38
51
 
39
- if config['strip']
40
- img.strip!
52
+ load_full_image unless @original_image_pixels_loaded
53
+
54
+ if @config['strip']
55
+ @original_image.strip!
41
56
  end
42
- i = img.scale(ratio)
57
+
58
+ i = @original_image.scale(ratio)
59
+
60
+ quality = size['quality'] || @config['default_quality']
61
+
43
62
  i.write(target_filepath) do |f|
44
63
  f.interlace = i.interlace
45
- f.quality = size['quality'] || config['default_quality']
64
+ f.quality = quality
46
65
  end
47
66
 
48
- if config['save_to_source']
67
+ if @config['save_to_source']
49
68
  # Ensure the generated file is copied to the _site directory
50
69
  Jekyll.logger.info "Copying resized image to #{site_dest_filepath}"
51
70
  FileUtils.copy_file(site_source_filepath, site_dest_filepath)
@@ -54,7 +73,7 @@ module Jekyll
54
73
  i.destroy!
55
74
  end
56
75
 
57
- img.destroy!
76
+ @original_image.destroy!
58
77
 
59
78
  resized
60
79
  end
@@ -65,8 +84,18 @@ module Jekyll
65
84
  Pathname.new(format % params).cleanpath.to_s
66
85
  end
67
86
 
68
- def needs_resizing?(img, width)
69
- img.columns > width
87
+ def needs_resizing?(width)
88
+ @original_image.columns > width
89
+ end
90
+
91
+ def load_full_image
92
+ @original_image = Magick::Image::read(@original_image_absolute_path).first
93
+ @original_image_pixels_loaded = true
94
+ end
95
+
96
+ def load_image_properties_only
97
+ @original_image = Magick::Image::ping(@original_image_absolute_path).first
98
+ @original_image_pixels_loaded = false
70
99
  end
71
100
 
72
101
  def ensure_output_dir_exists!(path)
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module ResponsiveImage
3
- VERSION = '1.5.5'.freeze
3
+ VERSION = '1.6.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-responsive-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Wynn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll