Search code examples
imagemagickimagemagick-convert

There is an option in ImageMagick that automatically cut out the written part of a page?


I use ImageMagick (with Windows 10) to convert my .pdf in .png, for example:

convert -background white -alpha remove -density 150 "mydoc.pdf" -quality 100 "mydoc.png"

I'd like to know if there is an option that automatically (that is without explicitly giving the size) cut out the written part of a page.

For example, from an image like this:

enter image description here

get an image like this:

enter image description here


Solution

  • What you are looking for is the -trim option:
    http://www.imagemagick.org/script/command-line-options.php#trim

    Simply add it to your command. You might also add the +repage option to reset the canvas offset:

    convert -background white -alpha remove -density 150 -trim +repage "mydoc.pdf" -quality 100 "mydoc.png"