> I have a question on copying a portion of an image in gimp.  First,   
> a little context.  I needed to create a layer with only some   
> features in an image.  For that, I first selected a suitable area in  
>  the image using the "Free Select" tool.  I then copied its contents  
>  (Edit -> Copy) and pasted it (Edit -> Paste) in a new layer (Layer   
> -> New Layer).  This creates a new layer with only the desired   
> features, as can be verified making the new layer the only visible   
> layer.  Now, if I go to the "Channel Dialog", I can see the RGB and   
> alpha channels looking right, with only the selected features there.  
>   However, if I make a copy of one of the RGB channels (right-click   
> on the R channel, for example, and duplicate it), there is more than  
>  just those features, as can be verified by making it the only   
> visible channel.
> My question then is if this is a correct behavior and if so, how can  
>  I make a copy of a selection with only the contents of that   
> selection?  Thank you,

First it should be realized that layers are always rectangular in  
shape. The new layer you created, even though it might an oval or some  
freedrawn shape, will still be rectangular (the smallest rectangle  
aligned with the XY-axes that fits the shape). The regions that lie  
outside of your selection but within the layer bounds still contain  
RGB data; however, the alpha channel is set to make those areas  
transparent. (You probably know this already, I just want to lay the  

As to whether the behavior of the thumbnail previews for the RGBA  
components is correct: well, sort of. What you are seeing in the  
Channels Dialog is that the thumbnail previews of the RGB components  
have the Alpha channel applied to them; even though the actual  
contents of the RGB channels are still there (the corresponding alpha  
data renders it transparent).

Even though the preview of the components don't display the RGB data,  
when you Duplicate the channel, that data (which was obscured by the  
alpha channel) gets copied to the duplicate.

http://flashingtwelve.brickfilms.com/GIMP/Temp/GIMP-challenge.png is a  
sample image that will demonstrate this clearly. The RGB data of the  
image contains a photo of the Eiffel Tower, however, the alpha channel  
is black rendering the image completely transparent (and the previews  
in the Channels dialog will all be black). If you duplicate the Red  
channel (as you did for your selection) then the new channel will  
contain the original red data of the Eiffel Tower picture.

As to how to make a channel (or selection) out of the contents of the  
selection, there are a few different approaches.

Using your technique to produce the Red channel duplicate (which  
includes extraneous RGB data), go back to your new layer and perform  
an alpha to selection. Then invert the selection, activate your Red  
channel duplicate, and perform an "Edit->Fill with BG Color" (assuming  
your BG is black).


After copying your selection to a new layer, perform a "Layer->Layer  
to Image Size" and drag it over to the Channels window. (If you want  
just the red channel data, you should hide the green and blue  
components and do a "Copy visible" when creating your new layer;  
otherwise your channel will be the overall RGB value.)


I wrote a script a while ago which creates a selection from a layer  
(or channel, or mask). It honors a selection if one exists (that is,  
the contents of the selected region become the selection) so if I am  
understanding you correctly, it might suit your needs. The file for  
the script is located at  
http://flashingtwelve.brickfilms.com/GIMP/Scripts/layer-select.scm and  
includes two other commands (all three commands are added to the  
"Select" menu), so I will just describe them briefly:

"Select->Layer bounds" -- simply selects the entire layer; sort of  
like Select->All but if you switch layers the selection stays the same.

"Select->To Layer" -- creates a new layer out of the selection using  
the FG and BG colors. Uses BG color to represent 'selected', so  
default colors generate a proper mask. The new layer has the same  
dimensions as the image.

"Select->From Drawable" -- creates a selection from the contents of  
the selected region.

Gimp-user mailing list

Reply via email to