Sha256: 8a08c761d45406ec64b45da345375a5f5da3ad68bd9bd8f2128be68e173ef71e

Contents?: true

Size: 584 Bytes

Versions: 1

Compression:

Stored size: 584 Bytes

Contents

require 'fastimage'
require 'uri'

module SpriteAnimationUtil
  class ImageSize
    def self.size(image_src)
      FastImage.size(parse_image_path(image_src), :raise_on_failure => true)
    end

    private

    def self.parse_image_path(image_src)
      if uri?(image_src)
        image_src
      else
        ::Rails.root.to_s+"/app/assets/images/#{image_src}"
      end
    end

    def self.uri?(string)
      uri = URI.parse(string)
      %w( http https ).include?(uri.scheme)
    rescue URI::BadURIError
      false
    rescue URI::InvalidURIError
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprite_animation-0.1.0 lib/sprite_animation/sprite_animation_util.rb