def python_colorize(image, layer):
"""Colorize plugin"""
image.disable_undo()
print(image, layer)
colorize.check_api_key()
# 1. Save actual image to GIMP TEMP direcotry as PNG
bw_photo = save_tmp_file(image, layer, image.filename)
print("Temp file saved in: " + bw_photo)
gimpfu.gimp.progress_init("Uploading image for processing.")
# 2. Upload file to the server
# gui_message(
# "Image is being processed at <u>{0}</u>.\nIt may take a while.".format(colorize.URL),
# gtk.MESSAGE_INFO
# )
# TODO: information window that data are uploaded.
download_url = colorize.upload_image(bw_photo)
if download_url == '': # if empty => error
gui_message(colorize.ALG_API_ERR, gtk.MESSAGE_ERROR)
gimpfu.gimp.quit()
else:
print("download_url: " + download_url)
# 3. Download it from the server
if download_url:
color_photo = colorize.download_image(download_url, bw_photo)
# 4. Display result as a new image
if color_photo:
gimpfu.gimp.Display(
gimpfu.pdb.file_png_load(color_photo, color_photo)
)
gimpfu.gimp.progress_init("Colorized data received...")
image.enable_undo()
####################
# Plug-in register #
####################
评论列表
文章目录