Gimp Python 脚本单独工作,但在组合时不工作

如何解决Gimp Python 脚本单独工作,但在组合时不工作

我有一个多层 Gimp XCF 模板,我的目标是自动将 JPG 插入其中并从命令行导出。

我有第一个工作 python-fu 插件用于插入图像,第二个工作 python-fu 插件用于展平/保存图像(一行执行的代码),但我想结合这两个插件来制作它们更容易从命令行调用。最终我还想自动打开 XCF 文件。现在虽然我只是想结合这两个功能。两个插件都接收“图像”和“层”作为输入参数。

我的组合插件的函数参数是图像、图层、要插入的 JPG(文件)、用于在 XCF 模板中放置图像的 X 和 Y 偏移量(x_offset、y_offset)以及导出位置(outputFolder) .

当我将保存命令(显示在代码底部附近的pdb.file_jpeg_save)添加到第一个工作脚本时,它失败了。为什么这会单独工作但在这里失败?

我的代码如下所示。

#!/usr/bin/env python

from gimpfu import *

def add_flatten_save(image,layer,file,x_offset,y_offset,outputFolder):
    ''' Add image to new layer,flatten,then saveSave the current layer into a PNG file,a JPEG file and a BMP file. '''

    # Indicates that the process has started.
    gimp.progress_init("Opening '" + file + "'...")

    try:
        # Open file.
        fileImage = None

        if(file.lower().endswith(('.jpeg','.jpg'))):
            fileImage = pdb.file_jpeg_load(file,file)

            # Create new layer.
            newLayer = gimp.Layer(image,"New Layer Name",layer.width,layer.height,layer.type,layer.opacity,layer.mode)
            # the +1 adds it behind the top layer
            image.add_layer(newLayer,+1)

            # Put image into the new layer.
            fileLayer = fileImage.layers[0]
            pdb.gimp_edit_copy(fileLayer)
            floating = pdb.gimp_edit_paste(newLayer,True)

            # Update the new layer.
            newLayer.flush()
            newLayer.merge_shadow(True)
            newLayer.update(0,newLayer.width,newLayer.height)

            # Flatten + offset floating layer,then flatten image
            pdb.gimp_floating_sel_to_layer(floating)
            pdb.gimp_layer_set_offsets(floating,y_offset)
            pdb.gimp_image_flatten(image)

            # Export JPG of flattened image
            pdb.file_jpeg_save(image,outputFolder + "/" + layer.name + ".jpg","raw_filename",0.9,"Creating with GIMP",0)

        else:
            gimp.message("The image could not be opened since it is not an image file.")

    except Exception as err:
        gimp.message("Unexpected error: " + str(err))
    
register(
    "python_fu_add_flatten_save","Add image to layer","Add image to layer and flatten.","Tim B.","2021","<Image>/Filters/Tim/Add,save","*",[
        (PF_FILE,"file","File to open",""),(PF_INT,"x_offset","X offset","y_offset","Y offset",(PF_DIRNAME,"outputFolder","Output directory",],[],add_flatten_save)

main()

解决方法

最根本的问题是,当您将图像展平时,图层“层”不再存在。

在保存之前尝试添加 layer = pdb.gimp_image_get_active_layer(image)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res