Gimp, python-fu: RuntimeError: execution error in pdb.gimp_image_merge_down
Gimp, python-fu: RuntimeError: execution error in pdb.gimp_image_merge_down
我的目标是将一张图片放在另一张图片上并将生成的图片保存为 jpeg 文件。
第一个是新的,它有 450x300 尺寸和白色背景。第二个是从文件加载的,它的可见部分作为一个层添加到第一个。
我已将以下 python 脚本添加到 /usr/lib/gimp/2.0/plug-ins 文件夹
#!/usr/bin/python
import os
from gimpfu import *
import gimpfu
import logging
def scale(timg, tdrawable, imageName):
logger = logging.getLogger()
logger.info('got logo file {0}'.format(imageName))
newImage = pdb.gimp_image_new(450, 300, RGB)
newLayer = pdb.gimp_layer_new(newImage, 450, 300, 0, "background", 100.0, NORMAL_MODE)
pdb.gimp_context_set_background((255, 255, 255))
pdb.gimp_drawable_fill(newLayer, gimpfu.BACKGROUND_FILL)
logger.info('Created new background image {0}')
newImage.add_layer(newLayer, 0)
timg = pdb.gimp_file_load(imageName, imageName)
tdraw = pdb.gimp_layer_new_from_visible(timg, newImage, 'logo')
newImage.add_layer(tdraw, 1)
finalLayer = pdb.gimp_image_merge_down(newImage,tdraw,1)
fileNameNoExt = os.path.splitext(imageName)[0]
pdb.file_jpeg_save(newImage, finalLayer, fileNameNoExt + '.jpg', fileNameNoExt + '.jpg', 1.0, 0.0, 1, 1, '', 0, 0, 0, 0)
运行 通过
gimp --no-interface -b '(python-fu-my RUN-NONINTERACTIVE 0 0 "logo.png")' -b '(gimp-quit 0)'
returns
(gimp:4224): GLib-CRITICAL **: g_error_new_literal: assertion 'domain
!= 0' failed Traceback (most recent call last): File
"/usr/lib/gimp/2.0/python/gimpfu.py", line 821, in _run return
apply(func, params[1:]) File "/usr/lib/gimp/2.0/plug-ins/my.py",
line 31, in scale finalLayer =
pdb.gimp_image_merge_down(newImage,tdraw,1) RuntimeError: execution
error batch command experienced an execution error: Error: ( : 1)
Procedure execution of python-fu-my failed
怎么了?如何正确的去做,了解问题的根本原因。
编辑。
按照 xenoid 的建议:
1) 使用 gimp_image_merge_down 结果 logo.jpeg 白色背景为 450, 300 size
def my(timg, tdrawable, imageName):
logger = logging.getLogger()
logger.info('got logo file {0}'.format(imageName))
newImage = pdb.gimp_image_new(450, 300, RGB)
newLayer = pdb.gimp_layer_new(newImage, 450, 300, 0, "background", 100.0, NORMAL_MODE)
pdb.gimp_context_set_background((255, 255, 255))
# pdb.gimp_context_set_foreground((255, 255, 255))
pdb.gimp_drawable_fill(newLayer, gimpfu.BACKGROUND_FILL)
logger.info('Created new background image {0}')
newImage.add_layer(newLayer, 0)
logger.info('loading logo {0}'.format(imageName))
logo = pdb.gimp_file_load(imageName, imageName)
# logoDrawable = pdb.gimp_image_get_active_layer(logo)
#
visibleLayer = pdb.gimp_layer_new_from_visible(logo, newImage, 'logo')
newImage.add_layer(visibleLayer, 1)
mergedL = pdb.gimp_image_merge_down(newImage, newLayer, 0)
fileNameNoExt = os.path.splitext(imageName)[0]
pdb.file_jpeg_save(newImage, mergedL, fileNameNoExt + '.jpg', fileNameNoExt + '.jpg', 1.0, 0.0, 1, 1, '', 0, 0, 0, 0)
2) 使用 newImage.add_layer(visibleLayer, 0) 结果原始 png 图像作为输入存储在 jpg格式
def scale(logo, tdrawable, imageName):
logger = logging.getLogger()
logger.info('got logo file {0}'.format(imageName))
newImage = pdb.gimp_image_new(450, 300, RGB)
newLayer = pdb.gimp_layer_new(newImage, 450, 300, 0, "background", 100.0, NORMAL_MODE)
pdb.gimp_context_set_background((255, 255, 255))
# pdb.gimp_context_set_foreground((255, 255, 255))
pdb.gimp_drawable_fill(newLayer, gimpfu.BACKGROUND_FILL)
logger.info('Created new background image {0}')
newImage.add_layer(newLayer, 0)
logger.info('loading logo {0}'.format(imageName))
logo = pdb.gimp_file_load(imageName, imageName)
# logoDrawable = pdb.gimp_image_get_active_layer(logo)
#
visibleLayer = pdb.gimp_layer_new_from_visible(logo, newImage, 'logo')
newImage.add_layer(visibleLayer, 0)
# mergedL = pdb.gimp_image_merge_down(newImage, newLayer, 0)
fileNameNoExt = os.path.splitext(imageName)[0]
pdb.file_jpeg_save(newImage, visibleLayer, fileNameNoExt + '.jpg', fileNameNoExt + '.jpg', 1.0, 0.0, 1, 1, '', 0, 0, 0, 0)
这个:
tdraw = pdb.gimp_layer_new_from_visible(timg, newImage, 'logo')
newImage.add_layer(tdraw, 1)
不将图层添加为顶层,而是在现有的顶层之下。如果它是第二层,那么它将成为最底层。在这种情况下 merge_down
没有任何可合并的东西。
我的目标是将一张图片放在另一张图片上并将生成的图片保存为 jpeg 文件。 第一个是新的,它有 450x300 尺寸和白色背景。第二个是从文件加载的,它的可见部分作为一个层添加到第一个。
我已将以下 python 脚本添加到 /usr/lib/gimp/2.0/plug-ins 文件夹
#!/usr/bin/python
import os
from gimpfu import *
import gimpfu
import logging
def scale(timg, tdrawable, imageName):
logger = logging.getLogger()
logger.info('got logo file {0}'.format(imageName))
newImage = pdb.gimp_image_new(450, 300, RGB)
newLayer = pdb.gimp_layer_new(newImage, 450, 300, 0, "background", 100.0, NORMAL_MODE)
pdb.gimp_context_set_background((255, 255, 255))
pdb.gimp_drawable_fill(newLayer, gimpfu.BACKGROUND_FILL)
logger.info('Created new background image {0}')
newImage.add_layer(newLayer, 0)
timg = pdb.gimp_file_load(imageName, imageName)
tdraw = pdb.gimp_layer_new_from_visible(timg, newImage, 'logo')
newImage.add_layer(tdraw, 1)
finalLayer = pdb.gimp_image_merge_down(newImage,tdraw,1)
fileNameNoExt = os.path.splitext(imageName)[0]
pdb.file_jpeg_save(newImage, finalLayer, fileNameNoExt + '.jpg', fileNameNoExt + '.jpg', 1.0, 0.0, 1, 1, '', 0, 0, 0, 0)
运行 通过
gimp --no-interface -b '(python-fu-my RUN-NONINTERACTIVE 0 0 "logo.png")' -b '(gimp-quit 0)'
returns
(gimp:4224): GLib-CRITICAL **: g_error_new_literal: assertion 'domain != 0' failed Traceback (most recent call last): File "/usr/lib/gimp/2.0/python/gimpfu.py", line 821, in _run return apply(func, params[1:]) File "/usr/lib/gimp/2.0/plug-ins/my.py", line 31, in scale finalLayer = pdb.gimp_image_merge_down(newImage,tdraw,1) RuntimeError: execution error batch command experienced an execution error: Error: ( : 1) Procedure execution of python-fu-my failed
怎么了?如何正确的去做,了解问题的根本原因。
编辑。 按照 xenoid 的建议: 1) 使用 gimp_image_merge_down 结果 logo.jpeg 白色背景为 450, 300 size
def my(timg, tdrawable, imageName):
logger = logging.getLogger()
logger.info('got logo file {0}'.format(imageName))
newImage = pdb.gimp_image_new(450, 300, RGB)
newLayer = pdb.gimp_layer_new(newImage, 450, 300, 0, "background", 100.0, NORMAL_MODE)
pdb.gimp_context_set_background((255, 255, 255))
# pdb.gimp_context_set_foreground((255, 255, 255))
pdb.gimp_drawable_fill(newLayer, gimpfu.BACKGROUND_FILL)
logger.info('Created new background image {0}')
newImage.add_layer(newLayer, 0)
logger.info('loading logo {0}'.format(imageName))
logo = pdb.gimp_file_load(imageName, imageName)
# logoDrawable = pdb.gimp_image_get_active_layer(logo)
#
visibleLayer = pdb.gimp_layer_new_from_visible(logo, newImage, 'logo')
newImage.add_layer(visibleLayer, 1)
mergedL = pdb.gimp_image_merge_down(newImage, newLayer, 0)
fileNameNoExt = os.path.splitext(imageName)[0]
pdb.file_jpeg_save(newImage, mergedL, fileNameNoExt + '.jpg', fileNameNoExt + '.jpg', 1.0, 0.0, 1, 1, '', 0, 0, 0, 0)
2) 使用 newImage.add_layer(visibleLayer, 0) 结果原始 png 图像作为输入存储在 jpg格式
def scale(logo, tdrawable, imageName):
logger = logging.getLogger()
logger.info('got logo file {0}'.format(imageName))
newImage = pdb.gimp_image_new(450, 300, RGB)
newLayer = pdb.gimp_layer_new(newImage, 450, 300, 0, "background", 100.0, NORMAL_MODE)
pdb.gimp_context_set_background((255, 255, 255))
# pdb.gimp_context_set_foreground((255, 255, 255))
pdb.gimp_drawable_fill(newLayer, gimpfu.BACKGROUND_FILL)
logger.info('Created new background image {0}')
newImage.add_layer(newLayer, 0)
logger.info('loading logo {0}'.format(imageName))
logo = pdb.gimp_file_load(imageName, imageName)
# logoDrawable = pdb.gimp_image_get_active_layer(logo)
#
visibleLayer = pdb.gimp_layer_new_from_visible(logo, newImage, 'logo')
newImage.add_layer(visibleLayer, 0)
# mergedL = pdb.gimp_image_merge_down(newImage, newLayer, 0)
fileNameNoExt = os.path.splitext(imageName)[0]
pdb.file_jpeg_save(newImage, visibleLayer, fileNameNoExt + '.jpg', fileNameNoExt + '.jpg', 1.0, 0.0, 1, 1, '', 0, 0, 0, 0)
这个:
tdraw = pdb.gimp_layer_new_from_visible(timg, newImage, 'logo')
newImage.add_layer(tdraw, 1)
不将图层添加为顶层,而是在现有的顶层之下。如果它是第二层,那么它将成为最底层。在这种情况下 merge_down
没有任何可合并的东西。