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');
精彩评论