Class: ShatteredMachine::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/shattered_machine/exchange.rb

Overview

Use the exchange algorithm from pnglitch on a given png image.

Constant Summary collapse

ALL_FILTERS =
%w[none sub up average paeth].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Exchange

Returns a new instance of Exchange.

Parameters:

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

    options for exchange algorithm



10
11
12
13
14
15
# File 'lib/shattered_machine/exchange.rb', line 10

def initialize(options = {})
  @filter = define_filter(options[:filter]) || 'average'
  @random = options[:random] || false
  @range = options[:range] || 0
  @seed = options[:seed] || 'x'
end

Instance Method Details

#call(input_image, output_image) ⇒ boolean

Returns status of exchange.

Parameters:

  • input_image (string)

    path for input image

  • output_image (string)

    path for output exchanged image

Returns:

  • (boolean)

    status of exchange



20
21
22
23
24
25
# File 'lib/shattered_machine/exchange.rb', line 20

def call(input_image, output_image)
  PNGlitch.open(input_image) do |png|
    filtered_glitch(png, @filter).save output_image
  end
  output_image
end