简体   繁体   English

Gimp,python-fu:RuntimeError:pdb.gimp_image_merge_down中的执行错误

[英]Gimp, python-fu: RuntimeError: execution error in pdb.gimp_image_merge_down

My goal is to put one image over the other and save the resulting image as jpeg file. 我的目标是将一个图像放在另一个图像上,并将结果图像另存为jpeg文件。 The first one is new one, it has 450x300 dimension and white background. 第一个是新的,它具有450x300尺寸和白色背景。 The second one is loaded from file and its visible part is added as a layer to the first. 第二个文件从文件加载,其可见部分作为图层添加到第一个文件中。

I have added the following python script to /usr/lib/gimp/2.0/plug-ins folder 我已将以下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)

Running it via 通过运行

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 (gimp:4224):严重问题**:g_error_new_literal:断言'domain!= 0'失败,回溯(最近一次调用最近):文件“ /usr/lib/gimp/2.0/python/gimpfu.py”,行821 ,在_run中返回apply(func,params [1:])文件“ /usr/lib/gimp/2.0/plug-ins/my.py”,第31行,比例为finalLayer = pdb.gimp_image_merge_down(newImage,tdraw,1 )RuntimeError:执行错误批处理命令遇到执行错误:错误:(:1)python-fu-my的过程执行失败

What is wrong? 怎么了? How to do it correctly and understand the root cause of the problem. 如何正确执行并了解问题的根本原因。

Edit. 编辑。 Following suggestions by xenoid : 1) Using gimp_image_merge_down results in logo.jpeg with white background of 450, 300 size xenoid的以下建议:1)使用gimp_image_merge_down生成带有450、300大小的白色背景的logo.jpeg

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) Using newImage.add_layer(visibleLayer, 0) results in original png image given as input stored in jpg format 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)

This: 这个:

tdraw = pdb.gimp_layer_new_from_visible(timg, newImage, 'logo')      
newImage.add_layer(tdraw, 1)

Doesn't add the layer as the top one, but under the existing top one. 不会将图层添加为顶层,而是添加到现有顶层之下。 If it's the second layer then it becomes the bottom one. 如果它是第二层,那么它将成为底层。 And in that case merge_down has nothing to merge on. 在那种情况下, merge_down没有任何要合并的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM