开发者

How can I detect borders of a piece of paper inside of an image and crop it using ImageMagick?

I'm trying to crop paper documents from photographs. For example, someone takes a picture of a document and sends it to the server and it will get edited 开发者_如何学Goto look like a scanned document. How can I detect the border of the document and crop it using ImageMagick?

Thanks


You want to use the convert command with the -trim option to crop out the solid color borders, and since the images are scanned, the -fuzz option to make sure trim completely crops the border even if the color isn't perfectly solid.

So something like this:

convert input.jpg -fuzz 2% -trim output.jpg

Translating that into PHP code, you'd end up with this:

$image = new Imagick('input.jpg');
$image->trimImage(2); // Trim the image with a 2% fuzz
$image->writeImage('output.jpg');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜