Class: Nanoc2::BinaryFilters::ImageScienceThumbnail

Inherits:
Nanoc2::BinaryFilter show all
Defined in:
lib/nanoc2/binary_filters/image_science_thumbnail.rb

Constant Summary

Constants inherited from Plugin

Plugin::MAP

Instance Method Summary collapse

Methods inherited from Nanoc2::BinaryFilter

#initialize

Methods inherited from Plugin

identifier, identifiers, named, register

Constructor Details

This class inherits a constructor from Nanoc2::BinaryFilter

Instance Method Details

#run(file) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nanoc2/binary_filters/image_science_thumbnail.rb', line 7

def run(file)
  require 'image_science'

  # Get temporary file path
  tmp_file = Tempfile.new('filter')
  tmp_path = tmp_file.path
  tmp_file.close

  # Create thumbnail
  ImageScience.with_image(file.path) do |img|
    img.thumbnail(@asset_rep.thumbnail_size || 150) do |thumbnail|
      thumbnail.save(tmp_path)
    end
  end

  # Return thumbnail file
  File.open(tmp_path)
end