4

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?

3

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.
  • 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 Feb 21 '16 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 Feb 21 '16 at 14:36
1

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
0

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, privacy policy and cookie policy

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