jina.types.document.converters module

jina.types.document.converters.uri_to_buffer(uri)[source]

Convert uri to buffer Internally it reads uri into buffer.

Parameters

uri (str) – the uri of Document

Return type

bytes

Returns

buffer bytes.

jina.types.document.converters.png_to_buffer(arr, width=None, height=None, resize_method='BILINEAR', color_axis=- 1)[source]

Convert png to buffer bytes.

Parameters
  • arr (ndarray) – Data representations of the png.

  • width (Optional[int]) – the width of the arr, if None, interpret from arr shape.

  • height (Optional[int]) – the height of the arr, if None, interpret from arr shape.

  • resize_method (str) – Resize methods (e.g. NEAREST, BILINEAR, BICUBIC, and LANCZOS).

  • color_axis (int) – the axis id of the color channel, -1 indicates the color channel info at the last axis

Returns

Png in buffer bytes.

..note::

if both width and height were provided, will not resize. Otherwise, will get image size by arr shape and apply resize method resize_method.

jina.types.document.converters.to_image_blob(source, color_axis=- 1)[source]

Convert an image buffer to blob

Parameters
  • source – image bytes buffer

  • color_axis (int) – the axis id of the color channel, -1 indicates the color channel info at the last axis

Return type

ndarray

Returns

image blob

jina.types.document.converters.to_datauri(mimetype, data, charset='utf-8', base64=False, binary=True)[source]

Convert data to data URI.

Parameters
  • mimetype – MIME types (e.g. ‘text/plain’,’image/png’ etc.)

  • data – Data representations.

  • charset (str) – Charset may be any character set registered with IANA

  • base64 (bool) – Used to encode arbitrary octet sequences into a form that satisfies the rules of 7bit. Designed to be efficient for non-text 8 bit and binary data. Sometimes used for text data that frequently uses non-US-ASCII characters.

  • binary (bool) – True if from binary data False for other data (e.g. text)

Returns

URI data