我正在尝试编写一个将创建位图字体的插件。但是,学习起来非常令人沮丧……虽然我不熟悉 python,但它并不难学,而且在 GIMP 之外也没有遇到过问题。
复制了一些代码:https://github.com/sole/snippets/blob/master/gimp/generate_bitmap_font/sole_generate_bitmap_font.py和http://gimpbook.com/scripting/
是否有效:
#!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def create_font(cwidth, cheight, font, size, color) :
#Set GLOBAL
char_begin = 32
char_end = 127
num_chars = char_end - char_begin
# Figure out total width & height
"""twidth = cwidth * 10
theight = cheight * 10
# Create Image
img = gimp.Image(cwidth * 10, cheight * 10, RGB)
img.disable_undo()
# Save the current foreground color:
pdb.gimp_context_push()
# Set the text color & background color
gimp.set_foreground(color)
gimp.set_background(0, 0, 0)
# Create All Layers & Position Accordingly
for i in range(char_begin, char_end):
string = '%c' % i
offset = i - char_begin
x_pos = offset * cwidth
y_pos = offset * cheight
text_layer = pdb.gimp_text_fontname(img, None, x_pos, y_pos, string, -1, False, size, PIXELS, font)
gimp.progress_update(float(offset) / float(num_chars))
pdb.gimp_image_flatten(img)
img.enable_undo()
# 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_bitmap_font",
"Bitmap Font",
"Create a new bitmap font",
"*****",
"*****",
"2013",
"Bitmap Font (Py)...",
"", # Create a new image, don't work on an existing one
[
(PF_SPINNER, "cwidth", "Cell Width", 24, (1, 3000, 1)),
(PF_SPINNER, "cheight", "Cell Height", 51, (1, 3000, 1)),
(PF_FONT, "font", "Font face", "Consolas"),
(PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
(PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
],
[],
create_font, menu="<Image>/File/Create")
main()
不工作:
#!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def create_font(cwidth, cheight, font, size, color) :
#Set GLOBAL
char_begin = 32
char_end = 127
num_chars = char_end - char_begin
# Figure out total width & height
twidth = cwidth * 10
theight = cheight * 10
# Create Image
"""img = gimp.Image(cwidth * 10, cheight * 10, RGB)
img.disable_undo()
# Save the current foreground color:
pdb.gimp_context_push()
# Set the text color & background color
gimp.set_foreground(color)
gimp.set_background(0, 0, 0)
# Create All Layers & Position Accordingly
for i in range(char_begin, char_end):
string = '%c' % i
offset = i - char_begin
x_pos = offset * cwidth
y_pos = offset * cheight
text_layer = pdb.gimp_text_fontname(img, None, x_pos, y_pos, string, -1, False, size, PIXELS, font)
gimp.progress_update(float(offset) / float(num_chars))
pdb.gimp_image_flatten(img)
img.enable_undo()
# 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_bitmap_font",
"Bitmap Font",
"Create a new bitmap font",
"*****",
"*****",
"2013",
"Bitmap Font (Py)...",
"", # Create a new image, don't work on an existing one
[
(PF_SPINNER, "cwidth", "Cell Width", 24, (1, 3000, 1)),
(PF_SPINNER, "cheight", "Cell Height", 51, (1, 3000, 1)),
(PF_FONT, "font", "Font face", "Consolas"),
(PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
(PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
],
[],
create_font, menu="<Image>/File/Create")
main()
似乎在将开始的注释从第 15 行更改为第 19 行之后,一切都陷入了困境。老实说,我什至不确定如何调试它。我尝试在 Filters>Python-Fu>Console 下使用控制台 - 但是这一直告诉我第 1 行是问题......我认为我们都同意并非如此。
我尝试在 python 脚本中运行这段代码,并且运行良好。
我应该怎么办?