Sha256: b7a8fb74f18d162278d4092b42359ae02ca8b14f5fddf7cae89d3f7430d351b1

Contents?: true

Size: 1.5 KB

Versions: 23

Compression:

Stored size: 1.5 KB

Contents

module Celerity

  class Image < Element
    include ClickableElement

    TAGS = [ Identifier.new('img') ]

    ATTRIBUTES = BASE_ATTRIBUTES | [:src, :alt, :longdesc, :name, :height, :width, :usemap, :ismap, :align, :border, :hspace, :vspace]
    DEFAULT_HOW = :src

    #
    # returns the file created date of the image
    #

    def file_created_date
      assert_exists
      web_response = @object.getWebResponse(true)
      Time.parse(web_response.getResponseHeaderValue("Last-Modified").to_s)
    end

    #
    # returns the file size of the image in bytes
    #

    def file_size
      assert_exists
      web_response = @object.getWebResponse(true)
      web_response.getContentAsBytes.length
    end

    #
    # returns the width in pixels of the image, as a string
    #

    def width
      assert_exists
      @object.getWidth
    end

    #
    # returns the height in pixels of the image, as a string
    #

    def height
      assert_exists
      @object.getHeight
    end

    #
    # returns true if the image is loaded
    #

    def loaded?
      assert_exists
      begin
        @object.getImageReader
        true
      rescue
        false
      end
    end

    #
    # Saves the image to the given file
    #

    def save(filename)
      assert_exists
      image_reader = @object.getImageReader
      file = java.io.File.new(filename)
      buffered_image = image_reader.read(0);
      javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
    end

  end # Image
end # Celerity

Version data entries

23 entries across 23 versions & 6 rubygems

Version Path
caius-celerity-0.0.6.10 lib/celerity/elements/image.rb
caius-celerity-0.0.6.11 lib/celerity/elements/image.rb
drnic-celerity-0.0.6.17 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.10 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.11 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.12 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.14 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.15 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.16 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.17 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.18 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.19 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.8 lib/celerity/elements/image.rb
jarib-celerity-0.0.6.9 lib/celerity/elements/image.rb
jarib-celerity-0.0.7.1 lib/celerity/elements/image.rb
regularfry-celerity-0.0.6.12 lib/celerity/elements/image.rb
walidhalabi-celerity-0.0.6.11 lib/celerity/elements/image.rb
walidhalabi-celerity-0.0.6.12 lib/celerity/elements/image.rb
walidhalabi-celerity-0.0.6.13 lib/celerity/elements/image.rb
celerity-0.7.4 lib/celerity/elements/image.rb