import os
import sys

input_path  = '@INPUT@'
output_path = '@OUTPUT@'
procedure   = Gimp.get_pdb().lookup_procedure("file-svg-load")
config      = procedure.create_config()
config.set_property("file", Gio.file_new_for_path(input_path))
config.set_property("width",  @LOGO_DIM@)
config.set_property("height", @LOGO_DIM@)
Gimp.Procedure.run(procedure, config)
v = Gimp.Procedure.run(procedure, config)

if v.index(0) != Gimp.PDBStatusType.SUCCESS:
  sys.exit(os.EX_SOFTWARE)

image = v.index(1)
image.resize(@IMG_WIDTH@, @IMG_HEIGHT@, (@IMG_WIDTH@-@LOGO_DIM@)/2, (@IMG_HEIGHT@-@LOGO_DIM@)/2)

procedure = Gimp.get_pdb().lookup_procedure("file-png-export")
config    = procedure.create_config()
drawables = image.list_selected_drawables()
# Needed otherwise it doesn't save the proper size because of bug #8855.
drawables[0].resize_to_image_size()
config.set_property("image", image)
config.set_property("num-drawables", len(drawables))
config.set_property("drawables", Gimp.ObjectArray.new(Gimp.Drawable, drawables, False))
config.set_property("file", Gio.file_new_for_path(output_path))
Gimp.Procedure.run(procedure, config)
