Is there an easy way to cut a slice from an image using Gimp?

10.2k Views Asked by At

Wondering if there is an easy way to remove a rectangular slice across the entire width of an image using Gimp, and have the resulting hole closed up automatically. I hope that makes sense. If I select a slice across an image and do "cut", it leaves a blank "hole" there. I want the new top and bottom of the image to join and fill that hole, reducing the image height by the amount sliced out.

Any easy way to do this?

4

There are 4 best solutions below

0
On BEST ANSWER

Here is a method that is quick and often does what you want:

  1. Cut out the middle, leaving a transparent "hole".
  2. Click anywhere to remove the selection (so the hole is not selected).
  3. Click Image > Zealous crop .

Zealous crop demo

This is going to remove the middle part. However, if you also have transparency in other parts of the image (like around the edges) it's going to remove that transparency too.

0
On

I believe you're asking to do something like cut out the middle of a page, leaving the header and footer and have the blank space removed with the cut action, effectively joining the header and footer together.

To my knowledge, I don't believe so. Even if you cut, or delete, that space is still part of the image even without content.

But, you would be able to highlight the top or bottom (or left or right) of the remaining space and drag it to align with the other side. It's not ideal for repetitive tasks, but should get you through if you only have to do it a few times.

0
On

Install Python and the Python Imaging Library. Back in GIMP, select and cut the full-width areas you don't want to transparent, and export the image to test.png. Then use this Python code (works only if complete lines are transparent; will not work properly if there are 100%-transparent pixels anywhere other than on a full-width row)—

from PIL import Image
i = Image.open("test.png")
b = i.tobytes()
b2 = ''.join(b[n:n+4] for n in xrange(0,len(b),4) if ord(b[n+3]))
newHeight = len(b2)/i.width/4
i2 = Image.frombytes('RGBA',(i.width,newHeight),b2)
i2.save("test.png")

Then re-load test.png and verify that the areas you cut have gone.

0
On

In gimp 2.8.1 you can easily create a new image from a selection. So if you select a rectangular than do a copy (Ctrl-C) and a past in a new image Edit -> Paste as -> new image (or Ctrl-Shift-V).