RSS/Atom feed Twitter
Site is read-only, email is disabled

[fix the script] copy a selection and paste as new layer..

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

3 of 3 messages available
Toggle history

Please log in to manage your subscriptions.

[fix the script] copy a selection and paste as new layer.. Choi, JiHui 14 Mar 10:10
[fix the script] copy a selection and paste as new layer.. saulgoode@flashingtwelve.brickfilms.com 15 Mar 08:01
  [fix the script] copy a selection and paste as new layer.. David Gowers 15 Mar 08:43
Choi, JiHui
2008-03-14 10:10:35 UTC (almost 17 years ago)

[fix the script] copy a selection and paste as new layer..

Hi, forks.

Here is a script. this copy a selection of the active layer and paste it as new layer with its opacity
made by Ankh (thank you, Ankh in #gimp, irc.gimp.org)

but there is a problem. size of the new layer is not its own size, is the same with the image. so I tried to fix this script, but I failed. T_T

please, fix it. and I want one more thing.

I'd like to add a function for pasting a content of clipboard as new layer. I failed, either -_-

these are very simple function, and I can do using some menus and keyboard shortcuts.
but sometime I need and repeating 2-3 steps makes me mad. please help me.

code:

; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ;
; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ;
; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;
;
; This script copies the visible layers contained within the active ; image and pastes the results into a single layer at the top of the stack ; of the active image It is an updated version of Karl Ward's merge-copy script ; which can be found here:
http://kward1979uk.deviantart.com/art/Merge-copy-28607825 ;
; The Script can be found in the Image's Edit Menu under the name: "Copy Visible & Paste"
;
; Special thanks to saulgoode at gimptalk.com for his suggestions on improving the script.

; Define the Function (define
(copy-paste-new-layer
inImage
inDraw)

; Declare the Variables (let*
((theHeight (car (gimp-image-height inImage))) (theWidth (car (gimp-image-width inImage))) (theFloatingSelection) ; an undefined variable to be defined below. (theType (car (gimp-drawable-type-with-alpha inDraw))) ; returns the drawables' type with an Alpha Channel (theSelection) ; undefined variable to contain the selected area in the image.
(theResult) ; undefined variable created below to hold the contents of the Copied Layers
(theOpacity (car (gimp-layer-get-opacity inDraw))) ; for layer opacity )

; Begin Undo Group
(gimp-image-undo-group-start inImage)

; Copy the selection from the current layer (gimp-edit-copy inDraw)

; Get the selected area in the image and save it to a channel (set! theSelection (car (gimp-selection-save inImage)))

; Create a new layer called "Cpoied Layer" to hold the pasted selection (set! theResult (car (gimp-layer-new inImage theWidth theHeight theType "Copied Layer" theOpacity NORMAL-MODE)))

; Fills theResult Layer (aka Copied Layer) with transparent fill (gimp-drawable-fill theResult TRANSPARENT-FILL)

; Adds theResult Layer to the active image (gimp-image-add-layer inImage theResult 0)

; Defines theFloatingSelection variable as containing the pasted layer and keeping the selection active (set! theFloatingSelection (car (gimp-edit-paste theResult FALSE)))

; Anchor theFloatingSelection to theResult (gimp-floating-sel-anchor theFloatingSelection)

; Reload the original selection (theSelection) (gimp-selection-load theSelection)

; Delete the channel holding the original selection (theSelection) (gimp-image-remove-channel inImage theSelection)

; End Undo Group (gimp-image-undo-group-end inImage))

; Update display (gimp-displays-flush))

(script-fu-register "copy-paste-new-layer" "/Edit/Copy/Copy & Paste as Layer" "Copies the selection to a new layer and pastes it in into active image"
"Art Wade"
"Art Wade"
"December 2007"
""
SF-IMAGE "SF-IMAGE" 0 SF-DRAWABLE "SF-DRAWABLE" 0

)

Greetings.

saulgoode@flashingtwelve.brickfilms.com
2008-03-15 08:01:01 UTC (almost 17 years ago)

[fix the script] copy a selection and paste as new layer..

Jihui Choi wrote:

Here is a script. this copy a selection of the active layer and paste it as new layer with its opacity
made by Ankh (thank you, Ankh in #gimp, irc.gimp.org)

but there is a problem.
size of the new layer is not its own size, is the same with the image. so I tried to fix this script, but I failed. T_T

The script you included copies the entire visible image to a new layer. It makes sense that the new layer is the size of the image since what you are copying may contain data outside the boundaries of the active layer.

David Gowers
2008-03-15 08:43:26 UTC (almost 17 years ago)

[fix the script] copy a selection and paste as new layer..

By the way people,

'copy visible' always copies the entire selection -- the resultant buffer always matches the selection bounds exactly.. When there is no selection this is naturally the full image size.

If you don't like this behaviour, you can use the Autocrop filter on the resultant image or layer.
(plug-in-autocrop, and plug-in-autocrop-layer)

On Sat, Mar 15, 2008 at 5:31 PM, wrote:

Jihui Choi wrote:

> Here is a script. this copy a selection of the active layer and paste > it as new layer with its opacity
> made by Ankh (thank you, Ankh in #gimp, irc.gimp.org)

> but there is a problem. > size of the new layer is not its own size, is the same with the image. > so I tried to fix this script, but I failed. T_T

The script you included copies the entire visible image to a new layer. It makes sense that the new layer is the size of the image since what you are copying may contain data outside the boundaries of the active layer.