Gimp Python-Fu
Grab most recent opened image
img = gimp.image_list()[0]
Iterate all opened images
for idx, immy_file in enumerate(gimp.image_list()):
print(idx, immy_file.name)
Move all image layers inside a new GroupLayer and vice versa
img = gimp.image_list()[0]
group = gimp.GroupLayer(img)
group.name = "Main Group Layer"
pdb.gimp_image_insert_layer(img, group, None, 0)
for idx, layer in enumerate(img.layers):
if not pdb.gimp_item_is_group(layer):
pdb.gimp_image_reorder_item(img, layer, group, 0)
# vice versa
for layer in group.layers:
pdb.gimp_image_reorder_item(img, layer, None, 0)
Slice to Layers
#image = gimp.image_list()[0]
def split_to_layers(total, chars_in_row, edge_in_pixels = 8, image = gimp.image_list()[0]):
base_layer = image.layers[0]
limit = chars_in_row * edge_in_pixels
x = 0
y = 0
for i in range(0, total):
pdb.gimp_image_select_rectangle(image, 2, x, y, edge_in_pixels, edge_in_pixels)
pdb.gimp_edit_cut(base_layer)
fsel = pdb.gimp_edit_paste(base_layer, False)
pdb.gimp_floating_sel_to_layer(fsel)
x = x + edge_in_pixels
if x == limit:
x = 0
y = y + edge_in_pixels
split_to_layers(62, 31)
BitmapFont Helper
img = gimp.image_list()[0]
mapped = {}
for idx, curr_layer in enumerate(img.layers):
if curr_layer.visible:
mapped['curr_layer'] = curr_layer
pdb.gimp_image_select_color(img, 2, curr_layer, (0, 0, 0))
pdb.gimp_drawable_edit_clear(curr_layer)
pdb.gimp_image_set_active_layer(img, curr_layer)
pdb.plug_in_autocrop_layer(img, curr_layer)
pdb.gimp_layer_resize(curr_layer, curr_layer.width + 2, curr_layer.height + 2, 1, 1)
cx = 0
cy = 0
max_width = img.width
for idx, curr_layer in enumerate(img. layers):
if curr_layer.visible:
if cx + curr_layer.width > max_width:
cx = 0
cy = cy + 7
curr_layer.set_offsets(cx, cy)
cx = cx + curr_layer.width
1 bit image to binary string
res = ""
for y in range(0, 4):
for x in range(0, 8):
res += str(min(lay.get_pixel(x, y)[0], 1))
# result
res [::-1]
'11010101100101011101011111010001'
BLENDER Mesh using bpy
import bpy
mesh = bpy.data.meshes.new("myBeautifulMesh") # add the new mesh
obj = bpy.data.objects.new(mesh.name, mesh)
col = bpy.data.collections["Collection"]
col.objects.link(obj)
bpy.context.view_layer.objects.active = obj
# from: https://elite.bbcelite.com/cassette/main/variable/ship_cobra_mk_3.html
verts = [
(32, 0, 76),
(-32, 0, 76),
(0, 26, 24),
(-120, -3, -8),
(120, -3, -8),
(-88, 16, -40),
(88, 16, -40),
(128, -8, -40),
(-128, -8, -40),
(0, 26, -40),
(-32, -24, -40),
(32, -24, -40),
(-36, 8, -40),
(-8, 12, -40),
(8, 12, -40),
(36, 8, -40),
(36, -12, -40),
(8, -16, -40),
(-8, -16, -40),
(-36, -12, -40),
(0, 0, 76),
(0, 0, 90),
(-80, -6, -40),
(-80, 6, -40),
(-88, 0, -40),
(80, 6, -40),
(88, 0, -40),
(80, -6, -40)
]
edges = [
(0, 1),
(0, 4),
(1, 3),
(3, 8),
(4, 7),
(6, 7),
(6, 9),
(5, 9),
(5, 8),
(2, 5),
(2, 6),
(3, 5),
(4, 6),
(1, 2),
(0, 2),
(8, 10),
(10, 11),
(7, 11),
(1, 10),
(0, 11),
(1, 5),
(0, 6),
(20, 21),
(12, 13),
(18, 19),
(14, 15),
(16, 17),
(15, 16),
(14, 17),
(13, 18),
(12, 19),
(2, 9),
(22, 24),
(23, 24),
(22, 23),
(25, 26),
(26, 27),
(25, 27)
]
mesh.from_pydata(verts, edges, [])