首页 文章

将透明度设置为不同颜色的背景imageMagick

提问于
浏览
1

我需要处理一些pdf到透明pngs pdf是纯文本的彩色背景 .

pdf有不同的彩色背景,有些是浅灰色,有些是白色等,但它们在整个pdf中是一致的 .

在imagemagick中是否有一种方法可以识别左上角的像素颜色,并在执行imagemagick命令时将获取的颜色传递给命令 -transparent "identifiedColor"

谢谢 !

1 回答

  • 3

    Solution 1: matte floodfill

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

    可能你必须调整模糊百分比

    更多细节:http://www.imagemagick.org/Usage/draw/#matte

    Solution 2: color replace

    我找不到在单个命令中执行此操作的方法,但这两个命令应该有效:

    • 用白色替换背景颜色(取自像素[0,0]):
    convert input.pdf -fill white -draw "color 0,0 replace" temp.png
    
    • 使白色像素透明:
    convert temp.png -transparent white output.png
    

    更多细节http://www.imagemagick.org/Usage/draw/#color

    在Windows上使用ImageMagick 6.6.0-1进行测试

相关问题