Sha256: e70cd65ef3f7e99ce3418dd1d22cd9f0a35f4505baf60e2da4459ca2ad59c062

Contents?: true

Size: 1.05 KB

Versions: 26

Compression:

Stored size: 1.05 KB

Contents

# -*- encoding : utf-8 -*-
# Does the same as the Pad tool but with absolute pixel values instead of fractionals
class Tracksperanto::Tool::Crop < Tracksperanto::Tool::Base
  
  parameter :top, :cast => :int, :desc => "Top crop amount in px"
  parameter :left, :cast => :int, :desc => "Left crop amount in px"
  parameter :right, :cast => :int, :desc => "Right crop amount in px"
  parameter :bottom, :cast => :int, :desc => "Bottom crop amount in px"
  
  def self.action_description
    "Crop or pad the image by a specified number of pixels"
  end
  
  def start_export(w, h)
    left_pad, right_pad, top_pad, bottom_pad = (left / w.to_f), (right / w.to_f), (top / h.to_f), (bottom / h.to_f)
    @pad = Tracksperanto::Tool::Pad.new(@exporter, :left_pad => left_pad, :right_pad => right_pad, :top_pad => top_pad, :bottom_pad => bottom_pad)
    @pad.start_export(w, h)
  end
  
  # Redirect all method calls to @pad instead of @exporter
  %w( start_tracker_segment end_tracker_segment export_point end_export).each do | m |
    define_method(m){|*a| @pad.send(m, *a)}
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
tracksperanto-3.2.2 lib/tools/crop.rb
tracksperanto-3.2.1 lib/tools/crop.rb
tracksperanto-3.2.0 lib/tools/crop.rb
tracksperanto-3.1.0 lib/tools/crop.rb
tracksperanto-3.0.1 lib/tools/crop.rb
tracksperanto-3.0.0 lib/tools/crop.rb