Class: Nutils::Filters::Crop

Inherits:
Nanoc3::Filter
  • Object
show all
Defined in:
lib/nutils/filters/crop.rb

Overview

Note:

Requires «RMagick»

Author:

  • Arnau Siches

Version:

  • 0.1.1

Instance Method Summary collapse

Instance Method Details

#run(filename, opts = {}) ⇒ File

Runs the content through RMagick#crop.

Parameters:

  • filename (String)

    The filename of the temporal file to filter.

  • params (Hash)

    a customizable set of options

Returns:

  • (File)

    The filtered content.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nutils/filters/crop.rb', line 33

def run(filename, opts = {})
  require 'RMagick'

  raise ArgumentError, "x, y, width and height are required parameters." unless opts[:x] and opts[:y] and opts[:width] and opts[:height]

  image = Magick::ImageList.new filename

  width = eval(opts[:width].to_s)
  height = eval(opts[:height].to_s)

  image.crop(opts[:x], opts[:y], width, height).write output_filename

rescue Exception => e
  raise ArgumentError, "#{e}\nSome parameters cannot be promoted to Integer."
end