It is currently Sat Jul 20, 2024 6:23 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to copy a selection from one image to another one
PostPosted: Wed Aug 24, 2016 4:31 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
GIMP Version: 2.8.18
Operating System: Windows
GIMP Experience: Basic Level



Likely a stupid question for a wise scripter, but for me that's the first time I have this need.
Assuming -
1) the filter receives an image (and a drawable) in input
2) the user made a selection on the input drawable before calling the filter
3) the filter becomes aware of this fact simply thru:
    (select, x1, y1, x2, y2) = pdb.gimp_drawable_mask_bounds (inDrawable)
    if select == True :    # there is a selection
        ......

4) the filter wants to keep the source image as it is and work on a new image, created with the same dimensions, and creates the background by copying the input drawable, like
    outImage = pdb.gimp_image_new (width, height, type)
    outBG = pdb.gimp_layer_new_from_drawable (inDrawable, outImage)

Now, the new image has no selection (it's not copied by the new_from_drawable statement).
Hence the question:
how can I copy the selection from the source so that the outBG is "exactly" corresponding to the source inDrawable?

Thanks a lot

_________________
"Where am I ?"


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: how to copy a selection from one image to another one
PostPosted: Wed Aug 24, 2016 7:06 am  (#2) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13080
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
dinasset wrote:
GIMP Version: 2.8.18
Operating System: Windows
GIMP Experience: Basic Level



Likely a stupid question for a wise scripter, but for me that's the first time I have this need.
Assuming -
1) the filter receives an image (and a drawable) in input
2) the user made a selection on the input drawable before calling the filter
3) the filter becomes aware of this fact simply thru:
    (select, x1, y1, x2, y2) = pdb.gimp_drawable_mask_bounds (inDrawable)
    if select == True :    # there is a selection
        ......

4) the filter wants to keep the source image as it is and work on a new image, created with the same dimensions, and creates the background by copying the input drawable, like
    outImage = pdb.gimp_image_new (width, height, type)
    outBG = pdb.gimp_layer_new_from_drawable (inDrawable, outImage)

Now, the new image has no selection (it's not copied by the new_from_drawable statement).
Hence the question:
how can I copy the selection from the source so that the outBG is "exactly" corresponding to the source inDrawable?

Thanks a lot


I'm not a script writer and don't know if this can be done with a script,
but you could create a path from the selection.
Export the path as a .svg file,
then import that .svg file to the new image.
Once the .svg file has been imported,
create the selection for this path in the new image.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: how to copy a selection from one image to another one
PostPosted: Wed Aug 24, 2016 8:02 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
- Duplicate the layer,
- invert the selection,
- "delete",
- layer_new_from_drawable(target_image) on the result and add to new image (if you want the selection in that new image, gimp-select-item on the layer)
- restore selection in initial image

_________________
Image


Top
 Post subject: Re: how to copy a selection from one image to another one
PostPosted: Wed Aug 24, 2016 8:47 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
thanks Wallace and Ofnuts.
I will try Ofnuts' solution, easier for me.

_________________
"Where am I ?"


Top
 Post subject: Re: how to copy a selection from one image to another one
PostPosted: Wed Aug 24, 2016 11:33 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Ofnuts,
I wrote a small filter to test your suggestion: everything OK, thanks a lot.

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Selection pasting only transparency - single layer image [Solved]

3

No new posts How to resize image after "paste into selection"?

2

No new posts Attachment(s) Path copy rotate shift plus + Path copy rotate shift walk Play

79

No new posts How to merge down layer copy

2

No new posts Copy Layer Group (SOLVED)

0



* Login  



Powered by phpBB3 © phpBB Group