分页: 1 / 1

ImageMagick使用笔记

发表于 : 2018年10月27日 10:51
paktc
1楼站位 + 索引

Re: ImageMagick使用笔记

发表于 : 2018年10月27日 10:52
paktc
自动裁剪图片周边的空白部分 -trim 参数

但是如果主体的边缘有暗影,怎么做呢?

http://www.imagemagick.org/Usage/crop/#trim
Trimming with fuzzy color selection -- Low Quality JPEG Images
Because JPEG is 'lossy' the colors in the image is generally not a single color but slightly varying band of different colors. because of this "-trim" will often fail for JPEG or real world images.

FUTURE: Example of failure here

As such you need to tell ImageMagick that colors that are not-exactly the same, but are reasonally close should be treated as being the same. Adding a very small "-fuzz" setting will do this.


convert image.jpg -fuzz 1% -trim +repage image_fuzzy_trim.jpg

It is also a very good idea to specify the specific color you want that fuzz to be relative to. This can be added by specifically added a border of that color using the "-border" operator. The border will of course always match the color to be trimmed, so will always be removed by "-trim".