11

I have multiple layers in my project. I need to crop one (call it layer A) to the size of another (layer B). Neither has the full size of the image. I thought I would switch to B, Select All, switch to A and Crop to Selection. However, when I switch to layer A, the selection changes to match all of layer A so that Crop to Selection does nothing. What am I missing?

4 Answers 4

8

It seems that there is no native way to do this, as the "Select All" feature makes a selection over the whole image area, resulting in an layer sized selection whenever you change the active layer.

Anyway, there are some possible ways:

  1. Workaround: If the layers does not contain transparency you can right-click on the layer in the layers dialog ([Ctrl + L]), and press 'Alpha to Selection' - On changing the active layer, the selection remains the same.
  2. Make it native with a plugin: If there is transparency a plugin does the job. I found 2 different plugins from Pedro Gimeno Fortea and Kevin Brubeck Unhammer (I only tested the one from Kevin Brubeck Unhammer beacause it seems to be newer (2012)). To install it, put the *.scm file in your gimp scripts folder (%APPDATA%/.gimp-[versionnumber]/scripts), and restart gimp. Now there should be a button Select > Layer to selection (The one on the very bottom) which produces a selection from the layer area - On changing the active layer, the selection remains the same.
2
  • 1
    I took inspiration from your workaround. The template layer had some transparency, but I added a solid-coloured mask to it, selected the whole mask with Fuzzy Select and then, when I switched to the target layer, the selection remained the same. Thinking about it, making a copy of the template layer, filling it which a solid color and doing Fuzzy Select would have worked the same. Hooray for workarounds! Thank you.
    – Frigo
    Commented Feb 21, 2016 at 14:31
  • I thought of the Fuzzy Select as well, but found it too clumsy (Without mask you would have to put the threshold to 255). For sure the best way is to install the plugin, as it adds the feature to gimp. - You're welcome
    – lcnittl
    Commented Feb 21, 2016 at 14:36
4

Both methods allow to crop a layer to the size of another even if they do not overlap. If they do, just skip the move steps.

If the first layer is an opaque rectangle:

  • Activate first layer (layer B) and Layer>Transparency>Alpha to selection. This creates a selection that exactly matches the layer.
  • If necessary:
    • Start the Move tool, and set it to Move selection (red square icon on the Move: line in the Tool options dialog
    • Use the Move tool to move the selection mask (ie, the "marching ants") and position it above the second layer.
  • Activate the second layer (Layer A) and Layer>Crop to selection

Another method (which will work even if the first layer isn't fully opaque):

  • Duplicate layer B
  • If necessary:
    • Position the layer B copy above layer A with the Move tool
  • If not fully opaque, bucket-fill with anything
  • Layer>Transparency>Alpha to selection
  • Delete the layer B copy
  • Activate the second layer (Layer A) and Layer>Crop to selection
2

Lets call the layer with the desired size and position SOURCE. And lets call the layer we want to crop the TARGET.

  1. Duplicate the SOURCE layer (Right click -> duplicate)
  2. Move the duplicated SOURCE layer to be below the TARGET layer (drag to change order)
  3. Hide all other layers except the duplicated SOURCE and the TARGET (using the eye icons)
  4. Right click on the layers -> Merge visible layers
    • Select "Clipped to bottom layer"
    • Click "Merge"
  5. Restore visibility of layers as it was

I also discovered that this flow can be used to export any part of the image defined by a layer. (This is was what I was after actually.)

For this you can select the "Discard invisible layers" in the layers merge dialog above.

Then you can do Canvas -> Fit canvas to layers and export from there.

Then hit Undo a couple of times to restore things to the state before the export.

1

I did it this way:

  • Select the layer in question (dotted frame appears)
  • Use 'select' tool, select an area just inside the layer edge
  • Zoom in to 800%
  • Manually expand the selection to pixel-match the layer
  • Crop to selection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.