Sha256: 0728c946911b65799205b50fab58153e2c7b175f08f0d488c7df56ead453856d

Contents?: true

Size: 840 Bytes

Versions: 1

Compression:

Stored size: 840 Bytes

Contents

class PSD
  class Slice
    attr_reader :id, :group_id, :origin, :associated_layer_id, :name, :type,
                :bounds, :url, :target, :message, :alt, :cell_text_is_html,
                :cell_text, :horizontal_alignment, :vertical_alignment,
                :color

    def initialize(psd, data)
      @psd = psd
      data.each do |k, v|
        instance_variable_set("@#{k}", v)
      end
    end

    [:left, :top, :right, :bottom].each do |dir|
      define_method(dir) { @bounds[dir] }
    end

    def width
      right - left
    end

    def height
      bottom - top
    end

    def associated_layer
      @psd.tree.find_by_id(associated_layer_id)
    end

    def to_png
      @png ||= @psd.image.to_png.crop(left, top, width, height)
    end

    def save_as_png(file)
      @png.save(file, :fast_rgba)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
psd-3.3.1 lib/psd/slice.rb