Module: Jekyll::Filters::Thumbnail
- Defined in:
- lib/jekyll/filters/thumbnail.rb
Overview
Liquid filter for use in templates
Instance Method Summary collapse
-
#thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil) ⇒ Object
Generates a thumbnail and returns its alternate destination.
Instance Method Details
#thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil) ⇒ Object
Generates a thumbnail and returns its alternate destination
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll/filters/thumbnail.rb', line 8 def thumbnail(input, width = nil, height = nil, crop = nil, auto_rotate = nil) return input unless input return input if input.downcase.end_with? '.gif' return input unless Jekyll.env == 'production' path = @context.registers[:site].in_source_dir input unless ::File.exist? path Jekyll.logger.warn "File doesn't exist #{input}" return input end image = Jekyll::Images::Cache.cached_image path thumb = image.thumbnail(width: width, height: height, crop: crop, auto_rotate: auto_rotate) thumb.write && thumb.optimize thumb.url rescue Vips::Error => e Jekyll.logger.warn "Failed to process #{input}: #{e.}" input end |