Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from gimpfu import *
def test(timg, tdrawable):
timg.undo_group_start() ### So that everything is undone with a single Ctrl-Z
gimp.context_push()
### bracket the code in a try/except
### Any error is caught in the "except" and the script exits cleanly
try:
#how to add alpha layer to my image?
### pdb.gimp_layer_add_alpha(tdrawable)
#how to apply "select by color" tool on a specified pixel and delete the selection from the whole image?
### See pdb.gimp_image_select_color(image, operation, drawable, color)
#determine the offset values manually
pdb.gimp_drawable_offset(tdrawable, 0, 1, 18, -32) ### These could be script parameters
#the image size is constant and 150x150 crops the border
### IMHO the gimp_drawable_offset above is superfluous, you can combine both if you don't use 150,150
pdb.gimp_image_crop(timg, 2400, 1200, 150, 150)
#guides using script-fu
pdb.script_fu_grid_guides(timg, 0, 150, 150, 1, 0)
#chop into 150x150 tiles
pdb.python_fu_ofn_guillotine_layer(timg, tdrawable)
#export all layers
pdb.python_fu_ofn_export_layers(timg, os.path.dirname(timg.filename), "{numUp0}.png", "-", 0)
except Exception as e:
trace(e.args[0])
gimp.message(e.args[0])
if debug:
traceback.print_exc()
gimp.context_pop()
timg.undo_group_end()
register(
"gg-test", # This one (aka "atom") should be unique across all scripts, so use a prefix
"test",
"test",
"*",
"*",
"2024",
"GGtest", # Only menu entry here
"*",
[
(PF_IMAGE, 'image', 'Input image', None), # Your "timg" arg
(PF_DRAWABLE, 'layer', 'Input layer', None), # Your "tdrawable" arg
],
[],
test,
menu="<Image>/Test" # Menu location here
)
main()
My own comments are prefixed with ###. Happy reading.