module Gtn::Images
Module to handle pre-calculating image dimensions We can then use those dimensions in the HTML to avoid reflow
Public Class Methods
# File _plugins/gtn/images.rb, line 44 def self._get_image_dimensions(path) cache.getset(path) do [FastImage.size(path), path] rescue StandardError Jekyll.logger.info "[GTN/Images] Could not resolve size of #{path}" end end
# File _plugins/gtn/images.rb, line 17 def self.cache @@cache ||= Jekyll::Cache.new('ImageDimensions') end
# File _plugins/gtn/images.rb, line 33 def self.get_image_dimensions(tuto_dir, url) if (match = url.match(%r{^{{\s*site.baseurl\s*}}/(.*)})) || (match = url.match(/{%\s*link\s*(.*)\s*%}/)) _get_image_dimensions(match[1].strip) elsif !url.match(%r{https?://}) img_path = File.absolute_path(File.join(tuto_dir, url)) _get_image_dimensions(img_path) if File.exist?(img_path) else _get_image_dimensions(img_path) end end
# File _plugins/gtn/images.rb, line 21 def self.html_image_dimensions(tuto_dir, url) return '' if !FASTIMAGE_AVAILABLE || (Jekyll.env == 'development') (width, height), path = get_image_dimensions(tuto_dir, url) return unless width && height [ %(width="#{width}" height=#{height}), path ] end