Sha256: 862c4af4760f1c4c47381ef5d489adeec884d5f193dd2767a5b999f92271d017

Contents?: true

Size: 1.61 KB

Versions: 41

Compression:

Stored size: 1.61 KB

Contents

module Frameit
  # Represents the MiniMagick trim bounding box for cropping a text image
  class Trimbox
    attr_accessor :width # width of the trim box
    attr_accessor :height # height of the trim box
    attr_accessor :offset_x # horizontal offset from the canvas to the trim box
    attr_accessor :offset_y # vertical offset from the canvas to the trim box

    # identify_string: A string with syntax "<width>x<height>+<offset_x>+<offset_y>". This is returned by MiniMagick when using function .identify with format("%@"). It is also required for the MiniMagick .crop function.
    def initialize(identify_string)
      UI.user_error!("Trimbox can not be initialised with an empty 'identify_string'.") unless identify_string.length > 0

      # Parse the input syntax "<width>x<height>+<offset_x>+<offset_y>".
      # Extract these 4 parameters into an integer array, by using multiple string separators: "x" and "+":
      trim_values = identify_string.split(/[x+]/).map(&:to_i)

      # If 'identify_string' doesn't have the expected syntax with 4 parameters, show error:
      UI.user_error!("Trimbox is initialised with an invalid value for 'identify_string'.") unless trim_values.length == 4

      # Assign instance variables:
      @width = trim_values[0]
      @height = trim_values[1]
      @offset_x = trim_values[2]
      @offset_y = trim_values[3]
    end

    # Get the trimbox parameters in the MiniMagick string format
    def string_format
      # Convert trim box parameters to string with syntax: "<width>x<height>+<offset_x>+<offset_y>":
      return "#{@width}x#{@height}+#{@offset_x}+#{@offset_y}"
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
fastlane-2.74.0.beta.20180106010004 frameit/lib/frameit/trim_box.rb
fastlane-2.73.0 frameit/lib/frameit/trim_box.rb
fastlane-2.73.0.beta.20180105010003 frameit/lib/frameit/trim_box.rb
fastlane-2.73.0.beta.20180104010004 frameit/lib/frameit/trim_box.rb
fastlane-2.73.0.beta.20180103010003 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0.beta.20180102010003 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0.beta.20180101010003 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0.beta.20171231010003 frameit/lib/frameit/trim_box.rb
fastlane-2.71.1 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0.beta.20171230010003 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0.beta.20171229010003 frameit/lib/frameit/trim_box.rb
fastlane-2.72.0.beta.20171228010004 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0.beta.20171227010004 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0.beta.20171226010004 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0.beta.20171225010003 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0.beta.20171224010003 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0.beta.20171223010003 frameit/lib/frameit/trim_box.rb
fastlane-2.71.0.beta.20171222010003 frameit/lib/frameit/trim_box.rb