Command line image manipulation

Dear Experts,

Is it possible via command line to rotate an image automatically so it is perfectly straight?  For example, lets say I scan in a document and the scan is slightly at an angle because the document was not inserted into the scanner properly.  I know you can rotate the image using something like this:

convert -rotate 90 input.jpg output.jpg

But is it possible to automatically detect how much it needs to be rotated by to straighten it up?

Who is Participating?
narmi2Connect With a Mentor Author Commented:
There is a way to have it rotate if the size meets criteria x.

See here.
narmi2Author Commented:
I can't figure out from that link how the program can automatically detect how much to rotate the scanned document to straighten it up.
I'm not sure how automatic it is based on your needs but the section that may be of use is the following.

as it says if you add -rotate -"90>" it will rotate and image if the width is more than the height. It's only automatic based on the criteria of either width less than height (>) or if width is less than height.

-rotate degrees{<}{>}
Apply Paeth image rotation (using shear operations) to the image.  

Use > to rotate the image only if its width exceeds the height. < rotates the image only if its width is less than the height. For example, if you specify -rotate "-90>" and the image size is 480x640, the image is not rotated. However, if the image is 640x480, it is rotated by -90 degrees. If you use > or <, enclose it in quotation marks to prevent it from being misinterpreted as a file redirection.

Empty triangles in the corners, left over from rotating the image, are filled with the background color.

See also the -distort operator and specifically the 'ScaleRotateTranslate' distort method.
narmi2Author Commented:
Here is an example scan image I want to straighten up

As you can see, this is slightly tilted.  Can the above commands straighten this up without me telling it how much to straighten it up by?
All Courses

From novice to tech pro — start learning today.