Sha256: 2c09583b4aa71f55d025c2b95e2f56cb92e1adbc3af68c8f3f2793285c9ef59a

Contents?: true

Size: 842 Bytes

Versions: 3

Compression:

Stored size: 842 Bytes

Contents

require 'oily_png'

module Gnawrnip
  class Image
    #
    # @parma [File] Screenshot image file (png)
    #
    def initialize(file)
      @file = file
      analysis
    end

    #
    # @return [Fixnum] Width of image
    #
    def width
      @dimension.width
    end

    #
    # @return [Fixnum] Height of image
    #
    def height
      @dimension.height
    end

    def to_base64
      Base64.strict_encode64(File.read(@file.path))
    end

    def resize(width, height)
      canvas.resample_bilinear(width, height).save(@file.path)
      analysis
    end

    def close!
      @file.close!
    end

    private

      #
      # Update dimension (OilyPNG::Dimension) of Image
      #
      def analysis
        @dimension = canvas.dimension
      end

      def canvas
        OilyPNG::Canvas.from_file(@file)
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gnawrnip-0.2.5 lib/gnawrnip/image.rb
gnawrnip-0.2.4 lib/gnawrnip/image.rb
gnawrnip-0.2.3 lib/gnawrnip/image.rb