You are here

Straighten and Crop

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!
StraightenAndCrop.zip6.08 KB

Update 10.6.2011 - the new version of the Straighten and Crop script (attached) will use the Python version of Post Rotate Crop if this is installed; otherwise it will use the Script-Fu version of the script. (The Python version of Post Rotate Crop is very much faster than the Script-Fu version)

A script that provides an easy method for straightening pictures and then, optionally cropping them to remove the resulting transparent areas.

The centre of rotation can be specified as can the type of cropping required.

The cropping can be performed by the GIMP rotate function but this can have unpredictable results. The Post Rotate Crop script provides more options and seems more reliable (let me know should you find a problem with it)

This version of Straighten and Crop uses the revised interface to the Post Rotate Crop script, including the option to select the aspect ratio of the cropped area.

The attached zip file includes the script and a text file of notes on its use.

Code License: 
GIMP Version: 
Scripting Engine: 


I'm using GIMP 2.8.0 and the script-fu version of post rotate crop. After using Deskew to rotate the .png image, I run PRC and get Error: -- (The drawable must have an alpha channel for the script to work) 0 . When I view the layers, I do have an alpha channel. Straighten and crop gives an identical error. My original image file contains only a gray layer. When I run the scripts on a color image originally containing red, green, blue and alpha layers, they work fine.

PRC relies on the corners from which the image has been rotated being transparent; it is for this reason that the image must have an alpha channel (before it is rotated).

in your image does not necessarily mean your image layer has alpha channel. Right-click on your layer containing image and add alpha channel to it.
Another way to check if the layer has an alpha channel: if the name of the layer is in bold font - no alpha, normal font - alpha channel is present

Your - very useful - script doesn't work anymore with Gimp 2.8 RC1, message:

Error: string->xxx: not a xxx 0-RC1

Any chance to fix this?

I will look at fixing this when the full release version is available.

I have now installed the release version of 2.8.0 by following the links from The initial testing that I have done shows no failures of the Straighten and Crop script or the Script-Fu version of Post Rotate Crop or the Python version of Post Rotate Crop. If you still have problems with these scripts when using the full release version please let me know - email me full details of how to reproduce the problem (possibly including screen shots of how you configure the dialogs) and I will attempt to sort it out.

I love this script for tweaking photos, but always end up scaling images back to original size which I like to do for consistency. I added a checkbox and related functionality to do this. It was not difficult but let me know if you want to incorporate it and I will send it to you.

That sounds like a good addition to the script. If you send me your version I will update the one posted here.

I have now discovered that the problems reported by payasam with my Post Rotate Crop script are actually due to their having the interpolation option for the rotate tool set to Sinc (Lanczos3). Using this interpolation method the corner pixels of the rotated image are not guaranteed to be totally transparent (have an alpha value of 0) even when the image is rotated about its centre. For instance when a 400 x 600 pixel image is rotated 0.7 degrees (clockwise) using the Lanczos3 interpolation algorithm the alpha values for pixels (0,0), (0,1), (0,2) and (0,3) are 2, 1, 0, 96 respectively; when Cubic interpolation is used the alpha values are 0, 0, 0, 80.

To me this indicates a bug in the Lanczos3 interpolation algorithm or the way in which the rotate tool uses the Lanczos3 algorithm.

I would therefore suggest that when using this Straighten and Crop script the interpolation type parameter should be set to Cubic and not to Sinc (Lanczos3).

I have updated the attachment. The script closes its undo group before calling Post Rotate Crop so that GIMP doesn't report an inconsistency if Post Rotate Crop has to report an error. Also limited the specified aspect ratio height and width to minimum values of 1.


Subscribe to Comments for "Straighten and Crop"