Class: JekyllRecker::Generators::ImageResize

Inherits:
Jekyll::Generator
  • Object
show all
Includes:
Base
Defined in:
lib/jekyll_recker/generators.rb

Overview

Image Resize Generator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Math

#average, #occurences, #total

Methods included from Logging

included, #info, #logger

Methods included from Date

#calculate_streaks, #slice_by_consecutive, #time_to_date

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



75
76
77
# File 'lib/jekyll_recker/generators.rb', line 75

def site
  @site
end

Instance Method Details

#generate(site) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/jekyll_recker/generators.rb', line 77

def generate(site)
  @site = Site.new(site)

  if @site.production?
    info 'production detected, skipping images'
    return
  end

  load_deps!

  info 'checking images'
  resizeable_images.each do |f, d|
    info "resizing #{f} to fit #{d}"
    image = MiniMagick::Image.new(f)
    image.resize d
  end
end

#graph?(file) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/jekyll_recker/generators.rb', line 104

def graph?(file)
  file.include?('/graphs/')
end

#load_deps!Object



99
100
101
102
# File 'lib/jekyll_recker/generators.rb', line 99

def load_deps!
  require 'fastimage'
  require 'mini_magick'
end

#resizeable_imagesObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/jekyll_recker/generators.rb', line 108

def resizeable_images
  without_graphs = site.images.reject { |i| graph?(i) }
  with_sizes = 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

Returns:

  • (Boolean)


95
96
97
# File 'lib/jekyll_recker/generators.rb', line 95

def too_big?(width, height)
  width > 800 || height > 800
end