import os
import sys

input1_path = '@TOP_SRCDIR@/gimp-data/images/logo/fileicon-base.svg'
input2_path = '@TOP_SRCDIR@/gimp-data/images/logo/gimp-logo-shadow.svg'
output_path = '@OUTPUT@'
procedure   = Gimp.get_pdb().lookup_procedure("file-svg-load")
config      = procedure.create_config()
size        = @LOGO_DIM@
config.set_property("file", Gio.file_new_for_path(input1_path))
config.set_property("width",  size)
config.set_property("height", size)
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)

config.set_property("file", Gio.file_new_for_path(input2_path))
wilber_size = size * 7 / 8
config.set_property("width",  wilber_size)
config.set_property("height", wilber_size)
Gimp.Procedure.run(procedure, config)
v = Gimp.Procedure.run(procedure, config)

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

tmp_image = v.index(1)
drawables = tmp_image.list_selected_drawables()
layer2 = Gimp.Layer.new_from_drawable (drawables[0], image)
image.insert_layer(layer2, None, 0)
layer2.set_offsets(0, (size - wilber_size) * 5 / 6)
tmp_image.delete()

image.merge_down(layer2, Gimp.MergeType.CLIP_TO_IMAGE)

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)

