Class: Nanoc::Filters::ImageCompressor

Inherits:
Nanoc::Filter
  • Object
show all
Defined in:
lib/nanoc/filters/image_compressor.rb

Constant Summary collapse

VERSION =
'0.1.1'

Instance Method Summary collapse

Instance Method Details

#run(filename, params = {}) ⇒ void

This method returns an undefined value.

Compresses the content with Sprockets::ImageCompressor.

Parameters:

  • filename (String)

    The filename to compress

  • params (Hash) (defaults to: {})

    Passed through to ImageOptim.new



19
20
21
22
23
24
25
26
27
28
# File 'lib/nanoc/filters/image_compressor.rb', line 19

def run(filename, params={})
  io = ImageOptim.new(params.merge(:threads => false))
  result = io.optimize_image(filename)
  path = result ? result.to_s : filename
  FileUtils.cp path, output_filename
  # ensure the output permissions match the input
  in_mode = File.stat(filename).mode & 0777
  out_mode = File.stat(output_filename).mode & 0777
  File.chmod(in_mode, output_filename) if in_mode != out_mode
end