Link to home
Start Free TrialLog in
Avatar of narmi2
narmi2

asked on

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?

Thanks
Avatar of Kruger_monkey
Kruger_monkey
Flag of United Kingdom of Great Britain and Northern Ireland image

There is a way to have it rotate if the size meets criteria x.

See here.

http://www.imagemagick.org/script/command-line-options.php?ImageMagick=hjg5196r7dlcfpti6df137psp5#rotate
Avatar of narmi2
narmi2

ASKER

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.
Avatar of narmi2

ASKER

Here is an example scan image I want to straighten up

http://www.jonbenetindexguide.com/10131999-HunterGJ-Announcement-Pg2.gif

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?
ASKER CERTIFIED SOLUTION
Avatar of narmi2
narmi2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial