GIMP Python-如果调用了一些pdb方法,Fu插件将不会注册
GIMP Python-Fu plugin will not register if some pdb methods are called
我正在尝试使用 Python-fu 进行一些批处理,但我的脚本无法运行。
当我尝试调用 pdb 中的一些方法时,例如 pdb.plug_in_nlfilt()
,插件不会注册。
我正在构建 test_batch_invert.py 示例 here。该示例有效并按预期处理文件,但下面的代码未注册。当我要处理图像时,所有这些 pdb 函数在 python 控制台中单独工作。
有什么想法吗?此外,当我注释掉所有有问题的 pdb 调用并且插件 does 注册时,它在菜单中显示为灰色,除非我有图像打开。有没有办法让它在菜单中正常运行而无需手动打开另一个图像文件?
谢谢大家!
-- 编辑:修复了名称 'layer' 的一些拼写错误,但这并没有解决问题。
#!/usr/bin/env python
# Repurposed from https://github.com/jfmdev/PythonFuSamples (see copyright at bottom)
import os
from gimpfu import *
def process_card(img, layer, inputFolder, outputFolder):
''' Display the message "Hello world" in the bottom of GIMP.
Parameters:
img : image The current image.
layer : layer The layer of the image that is selected.
'''
for file in os.listdir(inputFolder):
try:
# Build the full file paths.
inputPath = inputFolder + "\" + file
outputPath = outputFolder + "\" + file
# Open the file if is a JPEG or PNG image.
image = None
if(file.lower().endswith(('.png'))):
image = pdb.file_png_load(inputPath, inputPath)
if(file.lower().endswith(('.jpeg', '.jpg'))):
image = pdb.file_jpeg_load(inputPath, inputPath)
# Verify if the file is an image.
if(image != None):
if(len(image.layers) > 0):
layer = image.layers[0]
# THIS INVERT WORKS
pdb.gimp_invert(layer)
# (image, 2 for replace, x, y, width, height)
pdb.gimp_image_select_rectangle(image, 2, 865, 680, 1270, 2020)
# Including any of the rest of these pdb calls EXCEPT for pdb.file_jpg.save()
# will prevent plugin from registering.
pdb.gimp_selection_invert(image)
pdb.gimp_edit_clear(layer)
# Run alpha trimmed filter 3x
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 0)
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 0)
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 0)
#run optimal smoothing once
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 1)
#Edge enhance
pdb.plug_in_nlfilt(image, layer, 0.5, 0.7, 2)
#Select all
pdb.gimp_selection_all(image)
#zealous crop
pdb.plug_in_zealouscrop(image, layer)
#resize image
pdb.gimp_image_scale(image, 600, 955)
pdb.file_jpeg_save(image, layer, outputPath, outputPath, 0.9, 0, 0, 0, "Card", 0, 0, 0, 0)
except Exception as err:
gimp.message("Unexpected error: " + str(err))
register(
"python_fu_process_card",
"Card Scan",
"Process scanned image with jig, output to scaled jpg",
"My library",
"Open source (BSD 3-clause license)",
"2020",
"<Toolbox>/Filters/Process Card",
"*",
[
(PF_DIRNAME, "inputFolder", "Input directory", ""),
(PF_DIRNAME, "outputFolder", "Output directory", "")
],
[],
process_card)
main()
#
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2013, Jose F. Maldonado
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
# - Neither the name of the author nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
GIMP 详细输出提供的错误:
Querying plug-in: 'C:\Users\dried\AppData\Roaming\GIMP.10\plug-ins\img_BSG_card.py'
C:\Program Files\GIMP 2\bin\gimp-2.10.exe: LibGimpBase-WARNING: gimp-2.10.exe: gimp_wire_read(): error
对我有用,有点,经过几次修复后,但这些不是 PDB 调用:
您的注册声明了 2 个参数(输入和输出目录),您的函数需要 4 个。过去有默认的图像和图层参数,但注册规则随着时间的推移发生了一些变化。 Image 和 layer 作为前两个参数是专门处理的,但是如果你想要它们,你需要在注册中声明它们。菜单位置 <Toolbox>
自 Gimp 2.6 以来已弃用,因此您的示例已经过时了。
“\”作为文件分隔符在 Linux 和 OSX 上不起作用。 “/”在任何地方都有效,甚至在 Windows 上,但使用 os.path.join()
.
更合适
一旦完成,脚本就会为我运行(Linux 上的 Gimp 2.10.14)。我假设它会寻找具有特定特征的文件,因为如果它运行,结果会很奇怪:)
在您打开图像之前,菜单呈灰色,因为您的图像类型是 "*"
,它是任何类型的图像,而不是不需要任何类型的 ""
(空字符串)图片。
也就是说,您无需注册 script/plugin 即可在批处理模式下使用它,请参阅 示例。
在 Windows here.
上调试 Gimp python 脚本的一些提示
PS:据我所知,gimp_wire_read(): error
消息可以忽略,不是你的script/plugin.
造成的
我正在尝试使用 Python-fu 进行一些批处理,但我的脚本无法运行。
当我尝试调用 pdb 中的一些方法时,例如 pdb.plug_in_nlfilt()
,插件不会注册。
我正在构建 test_batch_invert.py 示例 here。该示例有效并按预期处理文件,但下面的代码未注册。当我要处理图像时,所有这些 pdb 函数在 python 控制台中单独工作。
有什么想法吗?此外,当我注释掉所有有问题的 pdb 调用并且插件 does 注册时,它在菜单中显示为灰色,除非我有图像打开。有没有办法让它在菜单中正常运行而无需手动打开另一个图像文件?
谢谢大家!
-- 编辑:修复了名称 'layer' 的一些拼写错误,但这并没有解决问题。
#!/usr/bin/env python
# Repurposed from https://github.com/jfmdev/PythonFuSamples (see copyright at bottom)
import os
from gimpfu import *
def process_card(img, layer, inputFolder, outputFolder):
''' Display the message "Hello world" in the bottom of GIMP.
Parameters:
img : image The current image.
layer : layer The layer of the image that is selected.
'''
for file in os.listdir(inputFolder):
try:
# Build the full file paths.
inputPath = inputFolder + "\" + file
outputPath = outputFolder + "\" + file
# Open the file if is a JPEG or PNG image.
image = None
if(file.lower().endswith(('.png'))):
image = pdb.file_png_load(inputPath, inputPath)
if(file.lower().endswith(('.jpeg', '.jpg'))):
image = pdb.file_jpeg_load(inputPath, inputPath)
# Verify if the file is an image.
if(image != None):
if(len(image.layers) > 0):
layer = image.layers[0]
# THIS INVERT WORKS
pdb.gimp_invert(layer)
# (image, 2 for replace, x, y, width, height)
pdb.gimp_image_select_rectangle(image, 2, 865, 680, 1270, 2020)
# Including any of the rest of these pdb calls EXCEPT for pdb.file_jpg.save()
# will prevent plugin from registering.
pdb.gimp_selection_invert(image)
pdb.gimp_edit_clear(layer)
# Run alpha trimmed filter 3x
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 0)
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 0)
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 0)
#run optimal smoothing once
pdb.plug_in_nlfilt(image, layer, 1.0, 1.0, 1)
#Edge enhance
pdb.plug_in_nlfilt(image, layer, 0.5, 0.7, 2)
#Select all
pdb.gimp_selection_all(image)
#zealous crop
pdb.plug_in_zealouscrop(image, layer)
#resize image
pdb.gimp_image_scale(image, 600, 955)
pdb.file_jpeg_save(image, layer, outputPath, outputPath, 0.9, 0, 0, 0, "Card", 0, 0, 0, 0)
except Exception as err:
gimp.message("Unexpected error: " + str(err))
register(
"python_fu_process_card",
"Card Scan",
"Process scanned image with jig, output to scaled jpg",
"My library",
"Open source (BSD 3-clause license)",
"2020",
"<Toolbox>/Filters/Process Card",
"*",
[
(PF_DIRNAME, "inputFolder", "Input directory", ""),
(PF_DIRNAME, "outputFolder", "Output directory", "")
],
[],
process_card)
main()
#
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2013, Jose F. Maldonado
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
# - Neither the name of the author nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
GIMP 详细输出提供的错误:
Querying plug-in: 'C:\Users\dried\AppData\Roaming\GIMP.10\plug-ins\img_BSG_card.py'
C:\Program Files\GIMP 2\bin\gimp-2.10.exe: LibGimpBase-WARNING: gimp-2.10.exe: gimp_wire_read(): error
对我有用,有点,经过几次修复后,但这些不是 PDB 调用:
您的注册声明了 2 个参数(输入和输出目录),您的函数需要 4 个。过去有默认的图像和图层参数,但注册规则随着时间的推移发生了一些变化。 Image 和 layer 作为前两个参数是专门处理的,但是如果你想要它们,你需要在注册中声明它们。菜单位置
<Toolbox>
自 Gimp 2.6 以来已弃用,因此您的示例已经过时了。“\”作为文件分隔符在 Linux 和 OSX 上不起作用。 “/”在任何地方都有效,甚至在 Windows 上,但使用
os.path.join()
. 更合适
一旦完成,脚本就会为我运行(Linux 上的 Gimp 2.10.14)。我假设它会寻找具有特定特征的文件,因为如果它运行,结果会很奇怪:)
在您打开图像之前,菜单呈灰色,因为您的图像类型是 "*"
,它是任何类型的图像,而不是不需要任何类型的 ""
(空字符串)图片。
也就是说,您无需注册 script/plugin 即可在批处理模式下使用它,请参阅
在 Windows here.
上调试 Gimp python 脚本的一些提示PS:据我所知,gimp_wire_read(): error
消息可以忽略,不是你的script/plugin.