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

copy-paste-anchor shifting my position

This discussion is connected to the gimp-developer-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.

4 of 4 messages available
Toggle history

Please log in to manage your subscriptions.

copy-paste-anchor shifting my position Roland Roberts 05 Sep 23:47
  copy-paste-anchor shifting my position Simon Budig 06 Sep 00:41
   copy-paste-anchor shifting my position Roland Roberts 06 Sep 02:32
    copy-paste-anchor shifting my position Simon Budig 06 Sep 08:49
Roland Roberts
2002-09-05 23:47:55 UTC (over 21 years ago)

copy-paste-anchor shifting my position

I'm trying to copy a layer from one image to another. Below is a fragment of the code to do this; new-image has already been created with the same base type as the old-image.

(set! new-layer (car (gimp-layer-new new-image (car (gimp-drawable-width old-layer)) (car (gimp-drawable-height old-layer)) (car (gimp-drawable-type old-layer)) (car (gimp-layer-get-name old-layer)) (car (gimp-layer-get-opacity old-layer)) (car (gimp-layer-get-mode old-layer))))) (gimp-layer-set-preserve-trans new-layer (car (gimp-layer-get-preserve-trans old-layer))) (gimp-layer-set-visible new-layer (car (gimp-layer-get-visible old-layer)))

;; Add the layer to the image copy. Then tweak the position to correspond to the ;; position in the old image.
(gimp-image-add-layer new-image new-layer -1) (gimp-selection-all new-image)
(gimp-edit-clear new-layer)
(gimp-selection-all old-image)
(gimp-edit-copy old-layer)
(gimp-floating-sel-anchor (car (gimp-edit-paste new-layer 1))) (apply gimp-layer-set-offsets (append (list new-layer) (gimp-drawable-offsets old-layer)))

I've taken the above and stepped through it one line at a time from the SIOD console. When I do the (gimp-floating-sel-anchor ...) the layer is misaligned compared to the original. The gimp-layer-set-offsets does nothing. Once the selection is anchored, that's where it stays. The layer I'm copying is the same size as the canvas and the same size as the background layer.

I also tried this interactively by selecting the whole canvas, copying the layer and pasting it into the new layer in the new image. It does the same thing, i.e., the layer is not ending up aligned the same as the original.

What am I doing wrong?

roland

Simon Budig
2002-09-06 00:41:12 UTC (over 21 years ago)

copy-paste-anchor shifting my position

Roland Roberts (roland@astrofoto.org) wrote:

I'm trying to copy a layer from one image to another. Below is a fragment of the code to do this; new-image has already been created with the same base type as the old-image.

[...]

(gimp-selection-all old-image)
(gimp-edit-copy old-layer)

It *might* (just tested with the GUI) be a better idea to use (gimp-selection-none old-image), since "If there is no selection, then the specified drawable's contents will be stored in the internal GIMP edit buffer" and gimp does not try to optimize the amount that gets stored in the buffer.

(gimp-floating-sel-anchor (car (gimp-edit-paste new-layer 1))) (apply gimp-layer-set-offsets (append (list new-layer) (gimp-drawable-offsets old-layer)))

Also you might want to use gimp-floating-sel-to-layer and use (gimp-layer-set-offsets ..) on this newly created layer. So you can avoid weird placement effects if the floating selection is smaller or bigger than the target layer.

However, it is an annoyance that gimp-layer-copy restricts the usage of the result to the originating image. This is weird, since the GUI can handle drag'n'drop of layers to other images quite fine.

Bye, Simon

Roland Roberts
2002-09-06 02:32:08 UTC (over 21 years ago)

copy-paste-anchor shifting my position

"Simon" == Simon Budig writes:

Simon> Roland Roberts (roland@astrofoto.org) wrote: >> I'm trying to copy a layer from one image to another. Below is a >> fragment of the code to do this; new-image has already been created >> with the same base type as the old-image. >>
Simon> [...]
>> (gimp-selection-all old-image) >> (gimp-edit-copy old-layer)

Simon> It *might* (just tested with the GUI) be a better idea to Simon> use (gimp-selection-none old-image), [...]

Thanks for this suggestion. It turns out that using gimp-selection-none on both the old and new images gets things pasted into the right locations.

Simon> Also you might want to use gimp-floating-sel-to-layer and Simon> use (gimp-layer-set-offsets ..) on this newly created Simon> layer. [...]

Naively using this results in twice as many layers as what I started with. And gimp-floating-sel-to-layer is documented to return nothing, so I'm not sure how I am supposed to find the newly created layer. Maybe I should have used gimp-selection-float to create the layer?

In any event, just removing the selection from both images results in an exact copy.

Simon> However, it is an annoyance that gimp-layer-copy restricts Simon> the usage of the result to the originating image. [...]

I agree...I first thought that was exactly what I wanted until I read the comments to realize I could only copy within an image.

roland

Simon Budig
2002-09-06 08:49:48 UTC (over 21 years ago)

copy-paste-anchor shifting my position

Roland Roberts (roland@astrofoto.org) wrote:

"Simon" == Simon Budig writes:

Simon> Also you might want to use gimp-floating-sel-to-layer and Simon> use (gimp-layer-set-offsets ..) on this newly created Simon> layer. [...]

Naively using this results in twice as many layers as what I started with.

gimp-image-merge-visible-layers helps :-)

And gimp-floating-sel-to-layer is documented to return nothing, so I'm not sure how I am supposed to find the newly created layer.

gimp-edit-paste returns a layer ID (the floating selection). I'd guess that the newly created layer keeps the ID of the floating selection.

Bye, Simon