سؤال

I need to process some pdfs to transparent pngs the pdfs are text-only with colored backgrounds.

The pdfs have varied colored backgrounds, Some are lightgray, some are white etc. but they are consistent throughout the pdf.

Is there a way in imagemagick where I can identify the left topmost pixel color and pass the acquired color to the command -transparent "identifiedColor" while executing the imagemagick command?

Thanks !

هل كانت مفيدة؟

المحلول

Solution 1: matte floodfill

convert input.pdf -fill none -fuzz 10% -draw "matte 0,0 floodfill" output.png

Probably you'll have to adjust fuzz percentage

more details here: http://www.imagemagick.org/Usage/draw/#matte

Solution 2: color replace

I could not find a way to do it in a single command, but these two commands should work:

  1. replace background color (taken from pixel[0,0]) with white:

    convert input.pdf -fill white -draw "color 0,0 replace" temp.png
    
  2. make white pixels transparent:

    convert temp.png -transparent white output.png
    

more details here http://www.imagemagick.org/Usage/draw/#color

Tested with ImageMagick 6.6.0-1 on Windows

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top