Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
small plugin code help
#2
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()
You main sin was a space missing. It is "import *" (import everything), not "import*"

My own comments are prefixed with ###. Happy reading.
Reply


Messages In This Thread
small plugin code help - by gimpygirl - 02-29-2024, 07:21 PM
RE: small plugin code help - by Ofnuts - 02-29-2024, 11:54 PM
RE: small plugin code help - by gimpygirl - 03-01-2024, 12:25 AM
RE: small plugin code help - by Ofnuts - 03-01-2024, 08:02 AM
RE: small plugin code help - by gimpygirl - 03-01-2024, 08:31 PM
RE: small plugin code help - by Ofnuts - 03-01-2024, 09:48 PM
RE: small plugin code help - by gimpygirl - 03-01-2024, 11:18 PM
RE: small plugin code help - by Ofnuts - 03-02-2024, 01:41 AM
RE: small plugin code help - by gimpygirl - 03-02-2024, 03:35 AM
RE: small plugin code help - by Ofnuts - 03-02-2024, 09:10 AM
RE: small plugin code help - by gimpygirl - 03-02-2024, 06:56 PM
RE: small plugin code help - by Ofnuts - 03-01-2024, 09:41 PM
RE: small plugin code help - by MrsP-from-C - 03-02-2024, 07:56 PM
RE: small plugin code help - by Ofnuts - 03-02-2024, 08:58 PM
RE: small plugin code help - by gimpygirl - 03-02-2024, 11:05 PM
RE: small plugin code help - by Ofnuts - 03-03-2024, 12:35 AM
RE: small plugin code help - by gimpygirl - 03-03-2024, 01:42 AM
RE: small plugin code help - by Ofnuts - 03-03-2024, 05:09 PM

Forum Jump: