INPUT /  OUTPUT /  LANGUAGE





img tag

Presentation tag

Displays a picture.

Sample usage

Fields

Primary field

Scalar field

The picture file's data, sent as raw data. PNG, JPEG, GIF (including animated GIFs) and SVG are supported.

Secondary fields

Behaviour

The picture is displayed at its own size unless width and height are given. Assigning new data to a named img replaces the picture.

The picture is drawn progressively as its data arrives. A picture that replaces a complete one appears once the new picture is complete; until then, the previous picture stays on screen.

To send a picture in pieces, clear the field, push each piece with .push, and then use .commit to show that the data is complete. The picture is drawn progressively as the pieces arrive, and is complete once it is committed.

The img tag does not generate a value.

Example

Sending a picture file from Python:

import sys

def print_raw(filename):
    with open(filename, 'rb') as f:
        data = f.read()
    print('[' + str(len(data)) + '{', end='', flush=True)
    sys.stdout.buffer.write(data)
    sys.stdout.buffer.flush()
    print('}]', end='', flush=True)

print('<img ', end='')
print_raw('photo.png')
print('>')

See also