Remove borders from image using ImageMagick convert

magician-cartoon-bw

Convert

ImageMagick’s “convert” application allows you to easily chop off pixels from the top and left sides using “-chop 5×5″ for example, however, there’s no method to chop from all four at once. It would seem obvious that “-chop 5×5x5×5″ would take off 5 pixels from all four sides, but it doesn’t work that way.

The easiest way to crop a border from an image is to rotate the image as you chop. It’s pretty much the same way you would cut a border from a piece of paper using a pair of scissors unless you were ambidextrous and even then wouldn’t it be faster to just rotate the picture rather than changing scissor hands?

All in one step

Chop, rotate, chop, rotate. Done.
$ convert -chop 10×10 -rotate 180 -chop 10×10 -rotate 180 orig.jpg temp.jpg

Individually it would be tedious

Chop 10 pixels from the top and left side of the original and save it in a temp file:
$ convert -chop 10×10 -rotate 180 orig.jpg temp.jpg

Chop 10 pixels from the bottom and right side of the temp and overwrite the original:
$ convert -chop 10×10 -rotate 180 temp.jpg orig.jpg

Batch border chopping

$ for x in `ls *.jpg`; do convert -chop 10×10 -rotate 180 $x $x_chop.jpg; done

Posted by admica   @   18 March 2010

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« YouTube: How to skip ahead to any part of a video
Next Post
Create photomosaic pictures with Metapixel »
Powered by Wordpress   |   Lunated designed by ZenVerse