Class: JekyllRecker::Generators::ImageResize
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- JekyllRecker::Generators::ImageResize
- Includes:
- Logging
- Defined in:
- lib/jekyll_recker/generators.rb
Overview
Image Resize Generator
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #generate(site) ⇒ Object
- #images_without_graphs ⇒ Object
- #resizeable_images ⇒ Object
- #too_big?(width, height) ⇒ Boolean
Methods included from Logging
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
71 72 73 |
# File 'lib/jekyll_recker/generators.rb', line 71 def site @site end |
Instance Method Details
#generate(site) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/jekyll_recker/generators.rb', line 73 def generate(site) @site = Site.new(site) if @site.production? && @site.recker_config.fetch('production_skip_images', true) info 'skipping image resizing (production)' else info 'checking images sizes' resizeable_images.each do |f, d| info "resizing #{f} to fit #{d}" image = MiniMagick::Image.new(f) image.resize d end end end |
#images_without_graphs ⇒ Object
91 92 93 |
# File 'lib/jekyll_recker/generators.rb', line 91 def images_without_graphs site.images.reject { |i| i.include?('/graphs/') } end |
#resizeable_images ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/jekyll_recker/generators.rb', line 95 def resizeable_images with_sizes = images_without_graphs.map { |f| [f, FastImage.size(f)].flatten } with_sizes.select! { |f| too_big?(f[1], f[2]) } with_sizes.map do |f, w, h| dimensions = if w > h '800x600' else '600x800' end [f, dimensions] end end |
#too_big?(width, height) ⇒ Boolean
87 88 89 |
# File 'lib/jekyll_recker/generators.rb', line 87 def too_big?(width, height) width > 800 || height > 800 end |