thorvg_python.saver

class thorvg_python.saver.Saver(engine: Engine, saver: SaverStruct | None = None)

Bases: object

Saver API

A module for exporting a paint object into a specified file.

The module enables to save the composed scene and/or image from a paint object. Once it’s successfully exported to a file, it can be recreated using the Picture module.

save(paint: Paint, path: str, compress: bool) Result

Exports the given paint data to the given path

If the saver module supports any compression mechanism, it will optimize the data size. This might affect the encoding/decoding time in some cases. You can turn off the compression if you wish to optimize for speed.

Parameters:
paint : Paint

The paint to be saved with all its associated properties.

path : str

A path to the file, in which the paint data is to be saved.

compress : bool

If true then compress data if possible.

Returns:

  • INVALID_ARGUMENT A nullptr passed as the argument.

  • INSUFFICIENT_CONDITION Currently saving other resources.

  • NOT_SUPPORTED Trying to save a file with an unknown extension or in an unsupported format.

  • UNKNOWN An empty paint is to be saved.

Return type:

Result

Note

Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call Saver.sync() afterwards.

See also

Saver.sync()

sync() Result

Guarantees that the saving task is finished.

The behavior of the Saver module works on a sync/async basis, depending on the threading setting of the Initializer. Thus, if you wish to have a benefit of it, you must call Saver.sync() after the Saver.save() in the proper delayed time. Otherwise, you can call Saver.sync() immediately.

Returns:

  • INVALID_ARGUMENT A nullptr passed as the argument.

  • INSUFFICIENT_CONDITION No saving task is running.

Return type:

Result

Note

The asynchronous tasking is dependent on the Saver module implementation.

See also

Saver.save()