class ShatteredMachine::WrongFilter

Use the wrong filter algorithm from pnglitch on a given png image.

Public Class Methods

new(options = {}) click to toggle source

@param options [Hash] options for wrong filter algorithm

# File lib/shattered_machine/wrong_filter.rb, line 8
def initialize(options = {})
  @filter = options[:filter] || 'average'
end

Public Instance Methods

call(input_image, output_image) click to toggle source

@param input_image [string] path for image @param output_image [string] path for output wrong filtered image @return [boolean] status of wrong filter

# File lib/shattered_machine/wrong_filter.rb, line 15
def call(input_image, output_image)
  PNGlitch.open(input_image) do |png|
    filtered_glitch(png, @filter).save output_image
  end
  output_image
end

Private Instance Methods

define_random_filter() click to toggle source
# File lib/shattered_machine/wrong_filter.rb, line 24
def define_random_filter
  available_filters = %w[none sub up average paeth]
  available_filters[rand(5)]
end
filtered_glitch(png, custom_filter) click to toggle source
# File lib/shattered_machine/wrong_filter.rb, line 29
def filtered_glitch(png, custom_filter)
  png.each_scanline do |scanline|
    if custom_filter == 'random'
      scanline.graft define_random_filter
    else
      scanline.graft custom_filter
    end
  end
end