Gimptalk - Premier Gimp Community: Copy Visible & Paste Script - Gimptalk - Premier Gimp Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Copy Visible & Paste Script

#1 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 20 December 2007 - 03:45 PM

This script is a simple one, yet very useful. The script copies all of the visible layers in the active image and pastes them into a single layer at the top of the layer stack (the new layer is called "Copied Layers"). This way, if you want to apply additional effects to the "current look" of your layers, you can do so in one simple step and, most importantly, keep your original layers intact. Also, if a selection is active at the time the script is run, only the selected area will be copied/pasted.

You can download it here: http://fence-post.de...Script-72552828

These steps can be done quite easily in GIMP (Copy Visible > Paste > Add New Layer > Anchor Floating Selection), but this really speeds things up.

Essentially, it is GIMP's version of Photoshop's Apply Image option (although I believe the PS version has more options....not sure on that though).

The inspiration for this script is from kward (http://kward1979uk.d...e-copy-28607825) who wrote the original version, but I've updated it to run in GIMP version 2.4. I've also modified the script to work on Grayscale and Indexed images.

Just download the zip file, double-click the zip file to open, and place the script (scm file) in your GIMP scripts folder (ie....C:\Program Files\GIMP-2.4\share\gimp\2.0\scripts)

Then, go to the main GIMP window (not the image window) and choose the Xtns Menu > Script-FU > Refresh Scripts and it should appear in the Image Window under the Edit Menu > Copy Visible & Paste as Layer

Enjoy!

Art
0

#2 User is offline   Fatal Edge 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 3,053
  • Joined: 11-June 06
  • LocationStaffordshire, England

Posted 20 December 2007 - 04:56 PM

I'm sure that this will be a very welcome script, especially for signature makers where applying effects to a copy visible layer is often used. The update to allow it to work on non-RGB images is also an excellent idea. If I hadn't already heavily modified kward's version I would have installed this.

I have a potential suggestion regarding the placement of the option within the menus. This may just be my personal preference, and it doesn't affect the functionality as such, so this would just be a personal preference choice. With my modified version of kward's script I have the command appearing amongst the other copy commands. See this:


Posted Image

If you think this is a good idea and want to implement it you just need to alter the menu registration as follows:

"/Edit/Copy/Copy Visible & Paste"

But anyway, an excellent script.

0

#3 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 20 December 2007 - 05:17 PM

Excellent tip! I wasn't aware you could specify it to be located in a sub-menu like that. That's pretty cool. I've modified the script accordingly.

Off-topic: I wasn't aware that you're no longer Insanity-Prevails here....just figured that out! :w:
0

#4 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 20 December 2007 - 05:22 PM

Hy fenceposte
i was hoping for something alike, i used very often that script, and the new options are cool

@Fatal Edge

Did you already posted your version of "copy merge" somewhere ? ...could you give me the link?
0

#5 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 20 December 2007 - 05:24 PM

Glad you found it useful, PC!

Art
0

#6 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 20 December 2007 - 07:04 PM

Art
i didn't know you know how wright script fu, a very nice surprise (same i could say for Fatal Edge :h:)

My suggestion is just for the name i think something as "Visible2NewLayer" may give a better hint of what the script does

But well also the actual name is clear...no so much for the original script name "copy-merged"
0

#7 User is offline   greentunic 

  • GT Moderator
  • Group: Moderators
  • Posts: 2,766
  • Joined: 20-May 07

Posted 20 December 2007 - 09:23 PM

Wow, thanks. This will definitely help a lot.
0

#8 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 20 December 2007 - 09:46 PM

@PhotoComix: This is only my second script....the Powertoning one (which is linked to the Powertoning tutorial on this site) was my first. My brain isn't really "wired" for programming so I have to take everything really slow, which is why my scripts are so simple. FatalEdge sounds like he's more wired for it, cuz his first few scripts appear quite sophisticated for someone who's new to the whole thing.

@greentunic: glad you like it!

Art
0

#9 User is offline   barbara 

  • Member
  • PipPip
  • Group: Members
  • Posts: 55
  • Joined: 07-November 05

Posted 20 December 2007 - 10:28 PM

Art,
this script is very very useful , thanks a lot !
(on Gimp 2.2 I used copy-merge script from kward every time I used Gimp :h: )
so thanks again
:h:
0

#10 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 20 December 2007 - 11:08 PM

I hope you won't mind if I offer a few pointers.

From the opening post:

Quote

Also, if a selection is active at the time the script is run, only the selected area will be copied/pasted.


I would assume the desired behavior is that the pasted layer appears in the same position as the original selection; however, your script will run into problems of the pasted layer being offset (from its original location) in certain situations. One situation is caused by the fact that GIMP tries to ensure that whenever something is pasted, the result lies within the view window so the user does not have to go looking for it. Another is that, in the event that the pasted buffer exceeds the boundaries of the active drawable, GIMP will center the pasted buffer over that drawable (horizontally, vertically, or both; as necessary).

Also, your script creates a new layer in the 'let*' block. This lies outside the UNDO group so the layer will not be "uncreated" if the user performs an UNDO. While there will be no apparent problem with this, the memory from that created layer will remain tied up until you close the GIMP (this is called a "memory leak"). For this reason, you should avoid creating layers (selections, masks, paths, etc) in your 'let*' block. Just declare 'theResult' variable in the 'let*' block and then create the new layer from within the UNDO grouping.

You probably should perform a 'gimp-displays-flush' at the end of your script. This will ensure that the image view and associated docks are updated.
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#11 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 20 December 2007 - 11:21 PM

@barbara: You're very welcome!

@saulgoode: Thanks for reviewing it and providing me with the feedback. I need all I can get! :w: I'll study your explanation a bit more tonight and modify the script accordingly to fix as you suggested. Being a non-programmer, even the simple stuff has been a challenge. I'm trying to read up on Scheme & Script-Fu programming resources (I've got tons of links), in hopes to put together tools that are not only functional, but are properly written. Your suggestion is one small step to a more properly written one! LOL (ok, I'm not really LOL'ing, but I always wanted to type that.)

BTW, do you have some suggestions for resolving the selection issue you addressed in your first paragraph? That part I'm not sure on how to fix.

Thanks again.

Art
0

#12 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 21 December 2007 - 12:43 AM

Quote

BTW, do you have some suggestions for resolving the selection issue you addressed in your first paragraph? That part I'm not sure on how to fix.


A good approach would be to save the selection to a channel, select none, copyvisible-n-paste to a new layer, then restore, invert, and clear the selection. This will work because the copy buffer (and resultant floating selection) will be the same size as the image, and not be offset. I wrote a similar script a couple of months back ("Image->Merge Visible to New Layer") that basically takes that approach, except that I don't actually invert and clear the selection (it is, of course, retained so that I can do that afterwards, should I wish).

Make sure that you "clean up" after you finish by restoring the original selection and removing the channel that your script created. My script used a named buffer (which I had to remove afterwards) because I did not want my default copy buffer to be affected by what I viewed as a merging of layers. It is reasonable that your script should modify the default copy buffer because it is viewed as a copy operation.

----------------

Can I ask why you ZIP your files? It would be preferable (to me) if I could just view it as a text page without downloading and UNZIPping -- I wouldn't even mind waiting those endless milliseconds for all those extra kilobytes. :l:
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#13 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 21 December 2007 - 04:03 PM

Thanks for the suggestions! I'll try working on implementing them this weekend. I have a suspicion this programming stuff may be more than my brain can handle. :w: Of course, I thought the same thing about GIMP back when I first started with it, so hopefully I'll get better as time goes on.

Quote

I wrote a similar script a couple of months back


Well, crud. I guess it really makes mine un-necessary. If I knew that one was available, I wouldn't have posted this one. But, nonetheless, it's a good learning experience, so all is not lost.

Quote

Can I ask why you ZIP your files?


Force of habit! At work, we're sending stuff back and forth between clients and everything's got to be zipped up due to filesize restrictions. Plus, I'm trying to do my part to preserve bandwidth. :l:

If you feel so inclined, you could take a look at my powertoning script and see if I've done anything incorrectly. I looked it over and but didn't see anything glaring, but after reviewing your above suggestions, I wonder if 2 of the variables I declared in the let* block are wrong. (I mean the script works fine on the surface, but from a programming standpoint it could create "problems".) That script can be found here: http://fence-post.de...Script-71897344. I've checked that one out and it's in scm format. Maybe you could brew some coffee while waiting for it to download!

Thanks for all the help. What a learning experience.

Art
0

#14 User is offline   PhotoComix 

  • GT Senior Moderator
  • Group: Senior Moderators
  • Posts: 11,288
  • Joined: 13-June 05

Posted 22 December 2007 - 05:07 AM

Hy Art
you may guess who requested that script ? :w:
Was something on top of my wishlist, ...and i was really happy then Kward wrote copy-merged

And i'm even more happy for copy visible & paste , i really missed something alike for gimp 2.4
to me should be bundled in Gimp,perfectly replace a missed feature equivalent to PS "Apply to Image" .
a perfect Christmas gift for my Gimp...:h:really welcome
0

#15 User is offline   Avenged 

  • Member
  • PipPip
  • Group: Members
  • Posts: 99
  • Joined: 09-December 07

Posted 24 December 2007 - 04:03 PM

Thank you for the script, works nice.
Posted Image
0

#16 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 26 December 2007 - 04:11 AM

Glad y'all have found the script a benefit. I'm just happy to get a successful script put together! :w: I've updated it now based on saulgoode's suggestions, but instead of allowing the script to copy & paste only the selected area, I just temporarily turned off the selection, stored it in a channel, and then turned the selection back on after the script is run. You can always invert > delete the selection if you so choose. IMO, this is probably the way the script will be used anyway. The script is also reposted in a non-zip format (per arm-twisting by saulgoode!)

@PhotoComix: Merry Christmas!! :l:

@saulgoode: Thanks again for the suggestions and letting me see your version, as that was a good learning opportunity in itself.

I noted that you used the procedure (I guess these a called procedures?):

gimp-edit-named-copy-visible & gimp-edit-named-paste whereas I used gimp-edit-copy-visible & gimp-edit-paste. In the procedure browser, I noted that your version stores the operations for later use regardless of cut or copy operations. Is there an advantage to using your way or is it a matter of preference?

I also like the way you didn't define a new layer in the script to which you would paste/anchor the contents, but used the gimp-floating-sel-to-layer float procedure to handle that in one step. Seems a lot easier/cleaner. But I just left my script as is, since there's no reason to make my script identical to yours.

Thanks a bunch.

Art
0

#17 User is offline   saulgoode 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 5,324
  • Joined: 22-August 05

Posted 26 December 2007 - 05:53 AM

Quote

You can always invert > delete the selection if you so choose. IMO, this is probably the way the script will be used anyway.


Indeed. Such an approach is also simplified if you have a script which will clear everything except the selected region. This was one of the first Script-fus I ever wrote and I find myself using it almost as much as I use "Edit->Clear" (http://flashingtwelv...ect-isolate.scm).

Quote

I noted that you used the procedure (I guess these a called procedures?):


I tend to call them "functions" since they can return values (in programming terminology, procedures do not generally return anything; they just "do" things), but "procedures" is fine (they are listed as such in the Procedural DataBase). To all the strange denizens of the world of lambda calculi, they are neither functions or procedures; they are semantically referred to as "closures" since they encapsulate a mutable environment space at the point of evaluation (and they don't really return values, they "evaluate to abstractions"). This is probably why nobody understands functional programming, including functional programmers.

Quote

gimp-edit-named-copy-visible & gimp-edit-named-paste whereas I used gimp-edit-copy-visible & gimp-edit-paste. In the procedure browser, I noted that your version stores the operations for later use regardless of cut or copy operations. Is there an advantage to using your way or is it a matter of preference?


The difference is that the default, unnamed copy buffer (often called a "clipboard") will not be modified as a side effect. It should not be assumed that a copy will be immediately followed by a paste, the user might very well do other things in the interim. Imagine if you performed a copy and then ran a script which, for example, pixelized your image; you would expect your clipboard contents to be unchanged. Since my script "merged layers", I wished the clipboard to be unchanged. Since your script performed a "copy" to a new layer, it might be expected to affect the clipboard (it might also be argued that it should not).
Everybody makes their own fun. If you don't make it yourself it's not fun, it's entertainment.
0

#18 User is offline   fencepost 

  • Retired Staff
  • PipPipPip
  • Group: Retired Staff
  • Posts: 2,643
  • Joined: 01-March 05

Posted 26 December 2007 - 09:49 PM

Quote

This is probably why nobody understands functional programming, including functional programmers.


:l:

Quote

The difference is that the default, unnamed copy buffer (often called a "clipboard") will not be modified as a side effect. It should not be assumed that a copy will be immediately followed by a paste, the user might very well do other things in the interim. Imagine if you performed a copy and then ran a script which, for example, pixelized your image; you would expect your clipboard contents to be unchanged. Since my script "merged layers", I wished the clipboard to be unchanged. Since your script performed a "copy" to a new layer, it might be expected to affect the clipboard (it might also be argued that it should not).


Makes perfect sense! Thanks for all your help.

Art
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic