02-29-2024, 07:21 PM (This post was last modified: 02-29-2024, 07:26 PM by gimpygirl.)
Hi
I have this plugin that just runs some other scripts and plugins.
I want to add the first 2 comments lines. Can somebody tell me if this is possible and fill in the required code?
The plugin works but the 2 first comment lines I don't know how to code it.
First I want to add an alpha layer to my image.
Then I want to apply "select by color" tool on a specified pixel (X and Y value of the pixel) and delete the selection from the whole image automatically? Is this possible using code?
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from gimpfu import*
def test(timg, tdrawable):
#how to add alpha layer to my image?
#how to apply "select by color" tool on a specified pixel and delete the selection from the whole image?
#determine the offset values manually
pdb.gimp_drawable_offset(tdrawable, 0, 1, 18, -32)
#the image size is constant and 150x150 crops the border
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)
02-29-2024, 11:54 PM (This post was last modified: 02-29-2024, 11:54 PM by Ofnuts.)
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.
03-01-2024, 08:31 PM (This post was last modified: 03-01-2024, 08:37 PM by gimpygirl.)
I understand it now!!!
All the GIMPies JUMP JUMP!!!
All the GIMPies JUMP JUMP!!!
All the GIMPies JUMP JUMP!!!
gimpygirl is doing the Kirby Dance
WooooWoooWoooWoooWooooooooooooooooooooooooooooooooo
I used the color picker, but then I suddenly see 2 ranges: 0..100 and 0..255
What is the 0..100 range???
So I just select a color with color picker and take the values of R, G and B in 0..255 range?
See screenshot: this color has 15, 15, 45 and then just this as RGB value in the code?
how to delete the selection from the image, made by gimp_image_select_color?
03-01-2024, 11:18 PM (This post was last modified: 03-02-2024, 12:00 AM by gimpygirl.)
(03-01-2024, 09:48 PM)Ofnuts Wrote:
(03-01-2024, 08:31 PM)gimpygirl Wrote:
how to delete the selection from the image, made by gimp_image_select_color?
You didn't search much, did you?
(from that point of view using Gimp in English helps a lot because the API names are quite close to the names in the English UI...)
Yes, I now see why I don't find anything
"clear" gives 0 results if you use another language!
You can't even find it when using translated words...
So I think I switch gimp to English
It doesn't work if I use this for selecting red. in gimp the selected color doesn't change (i have image opened)
03-02-2024, 01:41 AM (This post was last modified: 03-02-2024, 01:42 AM by Ofnuts.)
(03-01-2024, 11:18 PM)gimpygirl Wrote:
(03-01-2024, 09:48 PM)Ofnuts Wrote:
(03-01-2024, 08:31 PM)gimpygirl Wrote:
how to delete the selection from the image, made by gimp_image_select_color?
You didn't search much, did you?
(from that point of view using Gimp in English helps a lot because the API names are quite close to the names in the English UI...)
Yes, I now see why I don't find anything
"clear" gives 0 results if you use another language!
You can't even find it when using translated words...
So I think I switch gimp to English
It doesn't work if I use this for selecting red. in gimp the selected color doesn't change (i have image opened)
is correct, and it puts in the selection all the pixels that match red. But that doesn't update the foreground color... (if you use the By-color selection "manually" in the UI, it doesn't update the foreground color either). What you should see instead are the marching ants around the red areas.