You are here

Losing my mind trying to paste "INTO" a selection. Please help.

Alright so, I'm about to bite my screen at this point, this is driving me so mad.

Heres the function I want to replicate from Paint shop pro: Paste into selection.

Now you might say "but there is already a paste into selection in gimp?" but this does not function at all the same way...

For example, I have a piece of 30x30 pixel art, I open a different larger file, use the magic wand select to choose a large square area in the center of the card. I then want to simply choose paste into selection and have it resized to fit the LARGER area I have selected with the wand, without having to go through the current mess of steps where I paste it into the selection, it's still 30x30, so I have to resize the pasted image, then move it because it became off-center during the resizing, only to find out I didn't size it correctly, so it does not fit the area I need it to. Retry different percentage increase a few dozen times, scream and bash face into bed. repeat until nose bleeds.

I have about sixty pieces of art I need to do this for, and my (self imposed but still important) deadline is the end of this month.

I really hope there is some plugin that I can grab and make this as simple as it used to be on my old windows system (yeah, RIP.) or I'm just being an idiot and completely missing a command that is already in gimp which would let me do this.

Any help would be appreciated. Thanks.

placing just a pattern into a selection?
Save the smaller image as a pattern - edit/copy visible - edit/paste as pattern
It will be in the clipboard now.
Now just make your selection and go to Edit/Fill with pattern. :)

I don't mean a pattern, I mean to have it automatically scale into the selection, with the selection being it's new sizing. Like if i select a 360x360 area, then paste the 30x30 image into it, to have the originally 30x30 image become 360x360.

I need to place these 30x30 pieces of pixel art into these areas, and if there weren't extra steps, of paste, scaling, moving, and readjusting a mess of times it'd be much easier to ensure each of these is error free.

Saulgoode's script fit within a selection:

http://chiselapp.com/user/saulgoode/repository/script-fu/wiki?name=sg-la...

Once loaded is found in Layer - Fit Within Selection

It seems to have just added a different set of steps to the process, and the interpolation is botching up my images. Being that they are retro pixel art styled, no interpolation is the best interpolation.

If anybody knows of something else that can take copies from the clipboard, paste it into the dimensions of and centered within the current selection, with no interpolation, no pattern, that would be exactly what I need.

To take a small selected copy and enlarge it without stretching pixels? I don't think its possible. Anyone is welcomed to prove me wrong. Thanks, Saulgoode and Rob A!

Even up-scaling an image to a new selected area looks pretty good.I thought for sure stretching the pixels would cause problems.Nicely done AGAIN! *thumbs up*

In the script, change the two occurrences of INTERPOLATION-LANCZOS to INTERPOLATION-NONE . Then you just have to Edit->Paste, run the script ("Layer->Fit within Selection"), and Layer->New Layer.

Thanks saul, this works now too.

Here is a script that will do this, except it uses you current default interpolation, rather than none (this makes it more useful imoo):

Pastebin link: http://pastebin.com/fKUxE8Ag

or below:

; paste-into-selection.scm
; by Rob Antonishen
; http://ffaat.pointclark.net

; Version 1 (20110926)

; Description
;
; pastes the current buffer as a new layer scaled to the current selection, 
; above the current active layer, or scaled the canvas if there is no active layer.
; aspect ratio is preserved, and the current ddefault interpolation method is used.

; Changes

; License:
;
; 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.
;
; The GNU Public License is available at
; http://www.gnu.org/copyleft/gpl.html


(define (script-fu-paste-into-selection img drawable)

  (let* ((temp-image (car (gimp-edit-paste-as-new)))
         (active-layer (car (gimp-image-get-active-layer img)))
         (selection-info (gimp-selection-bounds img))
         (new-layer 0)
         (buffer-width 0)
         (buffer-height 0)
         (buffer-aspect 0)
         (offset-x 0)
         (offset-y 0)
         (saved-selection 0)
         (buffer-name "pis-buf"))

    (cond 
      ((= FALSE (car (gimp-image-is-valid temp-image)))
       (gimp-message "There is no image data in the clipboard to paste."))
       
      ((= TRUE (car (gimp-layer-is-floating-sel active-layer)))
       (gimp-message "The script doesn't work with floating selections."))
       
      (else
        (gimp-image-undo-group-start img)
        (set! buffer-width (car (gimp-image-width temp-image)))
        (set! buffer-height (car (gimp-image-height temp-image)))
        (set! buffer-aspect (/ buffer-width buffer-height))
        
        (if (= (car selection-info) FALSE) 
          (if (>= buffer-aspect (/ (car (gimp-image-width img)) (car (gimp-image-height img)))) ; if no selection
            (gimp-image-scale temp-image (car (gimp-image-width img)) (trunc (/ (* buffer-height (car (gimp-image-width img))) buffer-width)))
            (gimp-image-scale temp-image (trunc (/ (* buffer-width (car (gimp-image-height img))) buffer-height)) (car (gimp-image-height img)))
          )		  
          (if (>= buffer-aspect (/ (- (list-ref selection-info 3) (list-ref selection-info 1)) (- (list-ref selection-info 4) (list-ref selection-info 2)))) ; else (if selection)
            (gimp-image-scale temp-image (- (list-ref selection-info 3) (list-ref selection-info 1)) 
                                         (trunc (/ (* buffer-height (- (list-ref selection-info 3) (list-ref selection-info 1))) buffer-width)))
            (gimp-image-scale temp-image (trunc (/ (* buffer-width (- (list-ref selection-info 4) (list-ref selection-info 2))) buffer-height))
                                         (- (list-ref selection-info 4) (list-ref selection-info 2)))
          )
        )
        (set! buffer-name (car (gimp-edit-named-copy (car (gimp-image-get-active-layer temp-image)) buffer-name)))
        (set! buffer-width (car (gimp-image-width temp-image)))
        (set! buffer-height (car (gimp-image-height temp-image)))
        (gimp-image-delete temp-image)
        (set! new-layer (car (gimp-layer-new img buffer-width buffer-height (+ (* (car (gimp-image-base-type img)) 2) 1) "Clipboard" 100 NORMAL-MODE)))
        (gimp-image-add-layer img new-layer -1)		
        (if (= (car selection-info) FALSE) ; no selection
          (begin 
            (gimp-floating-sel-anchor (car (gimp-edit-named-paste new-layer buffer-name TRUE)))
            (if (= active-layer -1)
              (begin 
                (set! offset-x (round (/ (- (car (gimp-image-width img)) buffer-width) 2)))
                (set! offset-y (round (/ (- (car (gimp-image-height img)) buffer-height) 2))))
              (begin 
                (set! offset-x (+ (round (/ (- (car (gimp-drawable-width active-layer)) buffer-width) 2)) (car (gimp-drawable-offsets active-layer))))
                (set! offset-y (+ (round (/ (- (car (gimp-drawable-height active-layer)) buffer-height) 2)) (cadr (gimp-drawable-offsets active-layer)))))
            )
          )
          (begin  ;else selection
            (set! saved-selection (car (gimp-selection-save img)))
            (gimp-selection-none img)
            (gimp-floating-sel-anchor (car (gimp-edit-named-paste new-layer buffer-name TRUE)))
            (set! offset-x (+ (round (/ (- (- (list-ref selection-info 3) (list-ref selection-info 1)) buffer-width) 2)) (list-ref selection-info 1)))
            (set! offset-y (+ (round (/ (- (- (list-ref selection-info 4) (list-ref selection-info 2)) buffer-height) 2)) (list-ref selection-info 2)))
            (gimp-selection-load saved-selection)
            (gimp-image-remove-channel img saved-selection)
          )
        )
        (gimp-layer-translate new-layer offset-x offset-y)
        (gimp-image-set-active-layer img active-layer)
        (gimp-displays-flush)
        (gimp-image-undo-group-end img)
      )
    )
  )
)

(script-fu-register "script-fu-paste-into-selection"
  "Paste Into Current Selection"
  "Paste the clipboard contents scaled into the current selection"
  "Rob Antonishen"
  "Rob Antonishen"
  "2011-09"
  "*"
  SF-IMAGE      "image"      0
  SF-DRAWABLE   "drawable"   0
)

(script-fu-menu-register "script-fu-paste-into-selection"
                         "/Edit")

I tried installing your script, and I can't seem to find it anywhere in my gimp interface, I've tried installing other scripts (worked fine), restarting gimp, refreshing the scripts, and I can't seem to get yours to work. I don't know anything about scripting so I have no idea why it isn't showing up.

Under Edit - Paste into current selection (mine shows at the bottom of Edit)

Should you get it working, if you want to change interpolation methods, you can access that via Edit - Preferences - Tool Options.

http://docs.gimp.org/en/gimp-pimping.html#gimp-prefs-tool-options

Great script, Rob A!

weird, its there now! (I swear it wasn't a minute ago.) and it works!

Thanks for the script, Rob!

If you wrap your posted code within HTML "pre" tags, it will be presented in a fixed-width font with indentation retained.

I used code tags instead of pre tags. Seems I can't edit it not, but the pastebin link should be fine...

-Rob A>

I changed to pre tags for you, Rob.

Thanks - though I see little difference in my version of Firefox ;)

-Robv A>

Also, you might consider placing the command in the "Paste" subsection of the menu (with the other pasting commands):

(script-fu-menu-register "script-fu-paste-into-selection"
                         "/Edit/Paste")

shot in the duskiness
I had a go at a python script, mainly because this seems like a simple thing to tie together. It turned out to be a bit more troublesome than I thought (documentation seems outdated), but by scrapping a few of my initial requirements, I managed to get something that might be able to help you out. It is terribly hacky & dirty though. I hope you're on Linux, support for gimp & python on Windows seems dodgy at best.

Here's a link to the plugin:
http://hoekje.org/documents/scripts/paste-in-selection.py

Here's a link for plugin installation:
http://en.wikibooks.org/wiki/GIMP/Installing_Plugins
I just sudo mv'd the file to /usr/lib/gimp/2.0/plug-ins/ and made sure it was executable, i.e. chmod +x paste-in-selection.py. So:
wget http://hoekje.org/documents/scripts/paste-in-selection.py
chmod +x paste-in-selection.py
sudo mv paste-in-selection.py /usr/lib/gimp/2.0/plug-ins/

After installation, the 'plug-in' should show up in the Filters menu. Clicking it brings up a dialog in which you can select interpolation type and whether to merge the resulting floating selection with the current layer or not. (There is also a progress bar for some reason.) I tried to add an option to retain aspect, but it didn't quite work out (could add if needed). The plug-in assumes there is a selection (no error-handling there), gets the dimensions for that selection from GIMP, pastes from clipboard into a floating layer, resizes the floating layer to the dimensions of the selection, and if you chose to anchor the float - it anchors the float.

The best thing of all is that GIMP allows you to 'redo' a plugin with Ctrl-F - if this works for you, you should be done quickly.

(due to some difficulty with spamfilters, this post didn't make it quite on time - Rob's script seems a lot more sturdy :) - but am posting this for posterity. May someone have fun with it :} It was suggested that I refrain from using urls in my first post, so I removed the portion about installing)

I had a go at a python script, mainly because this seems like a simple thing to tie together. It turned out to be a bit more troublesome than I thought (documentation seems outdated), but by scrapping a few of my initial requirements, I managed to get something that might be able to help you out. It is terribly hacky & dirty though. I hope you're on Linux, support for gimp & python on Windows seems dodgy at best.

Here's the url for the plugin:
hoekje.org/documents/scripts/paste-in-selection.py

After installation, the 'plug-in' should show up in the Filters menu. Clicking it brings up a dialog in which you can select interpolation type and whether to merge the resulting floating selection with the current layer or not. (There is also a progress bar for some reason.) I tried to add an option to retain aspect, but it didn't quite work out (could add if needed). The plug-in assumes there is a selection (no error-handling there), gets the dimensions for that selection from GIMP, pastes from clipboard into a floating layer, resizes the floating layer to the dimensions of the selection, and if you chose to anchor the float - it anchors the float.

The best thing of all is that GIMP allows you to 'redo' a plugin with Ctrl-F - if this works for you, you should be done quickly.

Subscribe to Comments for "Losing my mind trying to paste "INTO" a selection. Please help."