<p>Try <code>-trim</code> instead of <code>-shave</code>:</p>

<pre><code>convert original.png -trim trimmed.png
</code></pre>

<p>See the <a href="http://www.imagemagick.org/Usage/crop/#trim" rel="nofollow">docs</a> for this and other options.</p>

CC BY-SA 3.0
2015-11-12T19:13:30.373Z
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`
Escher
CC BY-SA 3.0
2015-11-12T13:36:52.010Z
2015-11-12T13:36:52.010Z
lhf
<p>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:</p>

<pre><code>convert original.png -shave 10x10 shaved.png
</code></pre>

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

CC BY-SA 3.0
2015-11-16T09:49:11.447Z
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](http://superuser.com/questions/tagged/imagemagick).
Martin Ender
<edge-detection>
How to crop with edge-detection using imagemagick
Escher
# How to crop with edge-detection using imagemagick

(Asked by: username_0 on 2015-11-12)

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?

**Tags:** edge-detection

> **Comments:**
> **username_1**: 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](http://superuser.com/questions/tagged/imagemagick).  

---

## 1 answers

### Answer by username_2 on 2015-11-12. Score: 3 | Accepted answer

Try `-trim` instead of `-shave`:

```
convert original.png -trim trimmed.png

```

See the [docs](http://www.imagemagick.org/Usage/crop/#trim) for this and other options.

> **Comments:**
> **username_0**: 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`  

---

