Sha256: 7d8810e2239aa528ff09cf7c9b2e5c06622e9718d63e9048be93e1df5250d80c

Contents?: true

Size: 1.99 KB

Versions: 27

Compression:

Stored size: 1.99 KB

Contents

module Celerity

  class Image < Element
    include ClickableElement

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

    ATTRIBUTES = BASE_ATTRIBUTES | [
                                      :align,
                                      :alt,
                                      :border,
                                      :height,
                                      :hspace,
                                      :ismap,
                                      :longdesc,
                                      :name,
                                      :src,
                                      :usemap,
                                      :vspace,
                                      :width,
                                    ]
    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

27 entries across 27 versions & 3 rubygems

Version Path
celerity-0.8.9 lib/celerity/elements/image.rb
celerity-0.8.9.pre lib/celerity/elements/image.rb
celerity-0.8.8 lib/celerity/elements/image.rb
celerity-0.8.7 lib/celerity/elements/image.rb
celerity-0.8.6 lib/celerity/elements/image.rb
celerity-0.8.5 lib/celerity/elements/image.rb
celerity-0.8.4 lib/celerity/elements/image.rb
celerity-0.8.2 lib/celerity/elements/image.rb
celerity-0.8.1 lib/celerity/elements/image.rb
oki-celerity-0.8.2 lib/celerity/elements/image.rb
oki-celerity-0.8.1 lib/celerity/elements/image.rb
oki-celerity-0.8.1.dev lib/celerity/elements/image.rb
celerity-0.8.0 lib/celerity/elements/image.rb
celerity-0.8.0.beta.4 lib/celerity/elements/image.rb
celerity-0.8.0.beta.3 lib/celerity/elements/image.rb
celerity-0.8.0.beta.2 lib/celerity/elements/image.rb
celerity-0.8.0.beta.1 lib/celerity/elements/image.rb
fletcherm-culerity-0.2.9 vendor/gems/celerity-0.7.6/lib/celerity/elements/image.rb
fletcherm-culerity-0.2.8 vendor/gems/celerity-0.7.6/lib/celerity/elements/image.rb
celerity-0.7.9 lib/celerity/elements/image.rb