Let's say I have an image of an object against a white background. I want to crop so that the image fills the available space. This takes 10px off:

convert original.png -shave 10x10 shaved.png

How would I implement something like this that detects the edges of the object, thus cropping a variable number of pixels from each side?


closed as off-topic by Martin Ender Nov 16 '15 at 9:49

  • This question does not appear to be about computer graphics, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I'm closing this question as off-topic because it appears to be about using image processing software, not about computer graphics programming and research. This might be on topic on Super User. $\endgroup$ – Martin Ender Nov 16 '15 at 9:49

Try -trim instead of -shave:

convert original.png -trim trimmed.png

See the docs for this and other options.

  • $\begingroup$ Thanks, the docs recommended a fuzz factor. Combined with shaving border artifacts it worked perfectly. convert original.png -shave 5x5 -fuzz 1% -trim +repage trimmed.png $\endgroup$ – Escher Nov 12 '15 at 19:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.