我正在尝试使用 gimp 2.8.22 的功能将 pdf 转换为 jpeg,我想使用我的 windows cmd 中的 gimpfu 库使用 python 脚本来做到这一点(我已经安装了 python 3.6.1)。
现在,我不想用示例脚本来做到这一点:
#!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def hello_world(initstr, font, size, color) :
# First do a quick sanity check on the font
if font == 'Comic Sans MS' :
initstr = "Comic Sans? Are you sure?"
# Make a new image. Size 10x10 for now -- we'll resize later.
img = gimp.Image(1, 1, RGB)
# Save the current foreground color:
pdb.gimp_context_push()
# Set the text color
gimp.set_foreground(color)
# Create a new text layer (-1 for the layer means create a new layer)
layer = pdb.gimp_text_fontname(img, None, 0, 0, initstr, 10,
True, size, PIXELS, font)
# Resize the image to the size of the layer
img.resize(layer.width, layer.height, 0, 0)
# Background layer.
# Can't add this first because we don't know the size of the text layer.
background = gimp.Layer(img, "Background", layer.width, layer.height,
RGB_IMAGE, 100, NORMAL_MODE)
background.fill(BACKGROUND_FILL)
img.add_layer(background, 1)
# Create a new image window
gimp.Display(img)
# Show the new image window
gimp.displays_flush()
# Restore the old foreground color:
pdb.gimp_context_pop()
register(
"python_fu_hello_world",
"Hello world image",
"Create a new image with your text string",
"Akkana Peck",
"Akkana Peck",
"2010",
"Hello world (Py)...",
"", # Create a new image, don't work on an existing one
[
(PF_STRING, "string", "Text string", 'Hello, world!'),
(PF_FONT, "font", "Font face", "Sans"),
(PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
(PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
],
[],
hello_world, menu="<Image>/File/Create")
main()
我尝试从我的 cmd 运行脚本,如下所示:
gimp-2.8 --no-interface --batch '(python_fu_hello_world RUN-NONINTERACTIVE "Hello" Arial 50 red)' -b '(gimp-quit 1)'
但是,无论我做什么,我总是会收到相同的错误消息:
(gimp-2.8:1020): LibGimpBase-WARNING **: gimp-2.8: gimp_wire_read(): 错误
编辑:好的,谢谢。我省略了接口语句,还尝试了最简单的示例来找出问题所在:
#!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def hello_world():
gimp.message("Hello, GIMP world!\n")
register(
"hello_world",
'A simple Python-Fu "Hello, World" plug-in',
'When run this plug-in prints "Hello, GIMP world!" in a dialog box.',
"Tony Podlaski",
"Tony Podlaski 2017. MIT License",
"2017",
"Hello World",
"",
[],
[],
hello_world,
menu="<Image>/Filters/HelloWorld",
)
main()
当我从 Gimp 本身运行该脚本时,该脚本实际上可以工作,但是当我尝试从我的 cmd 运行它时,Gimp 打开另一个 cmd 并说:Error: ( : 1) eval: unbound variable: hello_world
有人知道我在这里缺少什么吗?