Skip to main content Link Search Menu Expand Document (external link)

ImageItem

MethodDescriptionOptionsExample
mime_typeGet the mime type for the image item.mine_type
bytesGet the bytes that comprise the image data item.bytes
updateUpdate the image with with a base 64 encoded image data item.update "data:image/png;base64,iVBO..."
update_from_bytesUpdate the image from a byte array, mime_type will be automatically detected unless specifiedmime_typeitem.update_from_bytes [0,23,45]...
update_from_fileUpdate the image from a file, mime_type will be automatically detected unless specifiedmime_typeitem.update_from_file '/tmp/foo.png'
update_from_urlUpdate the image from a url item.update_from_url 'https://www.foobar.com/baz.png'

Examples

Update from a base 64 encode image string

Image.update "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="

Update from image bytes and mime type

Image.update_from_bytes IO.binread(File.join(Dir.tmpdir,'1x1.png')), mime\_type: 'image/png'

Update from URL

Image.update_from_url 'https://raw.githubusercontent.com/boc-tothefuture/openhab-jruby/main/features/assets/1x1.png'

Update from File

Image.update_from_file '/tmp/1x1.png'

Log image data

logger.info("Mime type: #{Image.mime\_type}")
logger.info("Number of bytes: #{Image.bytes.length}")