Skip to main content

Replace a specific color in an Image

As the title suggests you can use a color picker to select a color in an image and replace it with something else. Maybe the image is just fine and you want to change the background which consists of a single color.

gowall convert ~/Pictures/bird.png -r #313244,#1D1C2D
gowall convert ~/Pictures/bird.png -r #313244,#1D1C2D --output ~/NewFolder/bird2.png

The above replaces the #313244 color in the image with #1D1C2D After converting an image to my favorite theme i dont like the background color being so bright.Lets fix that 🔨 Make sure to check out the threshold option too

replace color example

Threshold​

You can mess with the threshold that is accepted for a color to be replaced. To exaplin it simply, you see those petals in the image which look pink? Well you might think they are 1 color #F4BDCC but they might be different colors that are very close like #F4BDCD. By modifying the threshold value you can cover them as well.

gowall convert ~/Pictures/pixel_sakura_static.png -r #F4BDCC,#FF0000,30

The threshold is the third parameter in -r : #F4BDCC,#FF0000,30 <-- == #FromColor,#ToColor,Threshold (int)

  • The higher the threshold > 0 the more you accept nearby colors.
  • if the threshold is 0, then the image remains unchanged
Original ImageModified Image (Look at the red petals)
originalmodified

➤ Batch conversion​

gowall convert --batch bird.png,img2.png -r #313244,#1D1C2D
gowall convert --batch bird.png,img2.png -r #313244,#1D1C2D --output ~/NewFolder

➤ Directory conversion​

gowall convert --dir ~/Pictures/Dir -r #313244,#1D1C2D
gowall convert --dir ~/Pictures/Dir -r #313244,#1D1C2D --output ~/NewFolder