-
Notifications
You must be signed in to change notification settings - Fork 4
/
insertImagesToBackground.py
executable file
·39 lines (31 loc) · 1.14 KB
/
insertImagesToBackground.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#MenuTitle: Insert images in background
# -*- coding: utf-8 -*-
__doc__="""
In the dialog box select images to insert as background. Images must be named with the corresponding glyphname (ie. a.jpg) in case the glyph is not in the font the script will create it.
"""
from os import listdir
from os.path import splitext
from os.path import split
font = Glyphs.font
font.disableUpdateInterface()
paths = GetOpenFile(
message = "Select image:",
allowsMultipleSelection = True,
filetypes = ["jpeg", "png", "tif", "gif", "pdf"]
)
for imageFilePath in paths:
fileName = split(imageFilePath)
glyphName = splitext(fileName[1])[0]
if glyphName in font.glyphs:
thisGlyph = font.glyphs[glyphName]
for layer in thisGlyph.layers:
layer.backgroundImage = GSBackgroundImage(imageFilePath)
thisGlyph.updateGlyphInfo()
else:
font.glyphs.append(GSGlyph(glyphName))
thisGlyph = font.glyphs[glyphName]
for layer in thisGlyph.layers:
layer.backgroundImage = GSBackgroundImage(imageFilePath)
thisGlyph.updateGlyphInfo()
print ("Added image to", glyphName, "background. Be sure to have View> Show image activated.")
font.enableUpdateInterface()