Gimp 3.x Python-Fu
Grab most recent opened image
image = Gimp.get_images()[0]
Iterate all opened images
for immy in Gimp.get_images():
print(immy.get_name())
Save file (.xcf)
image = Gimp.get_images()[0]
image.is_dirty()
new_file = Gio.File.new_for_path("/home/USER/Graphics/using_gimp/from_console.xcf")
Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, image, new_file, None)
#Gimp.RunMode.INTERACTIVE # == 0
#Gimp.RunMode.NONINTERACTIVE # == 1
#Gimp.RunMode.WITH_LAST_VALS # == 2
file = image.get_xcf_file()
file.get_basename()
#'from_console.xcf'
file.get_path()
Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, image, file, None)
image.is_dirty()
image.clean_all()
Slice to Layers
image = Gimp.get_images()[0]
source_layer = image.get_layers()[0]
x = 0
y = 0
width = 8
height = width
rows = 32
cols = 3
for i in range(rows * cols):
# Gimp.ChannelOps.ADD: 0
# Gimp.ChannelOps.SUBTRACT: 1
# Gimp.ChannelOps.REPLACE: 2
# Gimp.ChannelOps.INTERSECT: 3
image.select_rectangle(Gimp.ChannelOps.REPLACE, x, y, width, height)
Gimp.edit_cut([source_layer])
fsel = Gimp.edit_paste(source_layer, True)
Gimp.floating_sel_to_layer(fsel[0])
image.get_layers()[i].set_name(chr(i+32))
x += width
if x == rows * width:
x = 0
y += height
Gimp.Selection.none(image)