首页 > 解决方案 > Can I edit an image file from command line?

问题描述

As a school project, I need to automatically edit image files by bringing little changes to them. To be more specific, at this early stage I'd be happy to just apply the Bucket fill option to some areas (the areas and the color would be decided at runtime of the shell script). I wonder if there is a utility or a program that allows to be executed via the command line and to apply the desired changes if written from the shell/in a shell script.

(In case it matters, I can work on either Linux or Windows)

标签: bashshell

解决方案


In ImageMagick 6, you can flood fill a region with another color as

convert image.suff -fuzz XX% -fill red -draw "color x,y floodfill" -alpha off result.suffix

The above command will fill red color starting at coordinates x,y and stopped when any color in the image nearby exceeds the threshold values XX% from the -fuzz values.

Example:

enter image description here

convert color_test.png -fuzz 0% -fill white -draw 'color 30,20 floodfill' -alpha off color_floodfill.png

enter image description here

See https://imagemagick.org/Usage/draw/#color

If using ImageMagick 7, change convert to magick (and not magick convert)


推荐阅读