问题
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 to look like a scanned document. How can I detect the border of the document and crop it using ImageMagick?
Thanks
回答1:
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');
来源:https://stackoverflow.com/questions/7063415/how-can-i-detect-borders-of-a-piece-of-paper-inside-of-an-image-and-crop-it-usin