Mass recoloring of PNGs from command line

7

1

Similar to the mass rescaling command this site taught me here, is there a command-line trick for mass recoloring?

To make it specific, suppose I have a bunch of images with RGB and alpha values:

apple_original.png  
pear_original.png  
banana_original.png 

and so on. I want to have a command-line command to give me the following:

apple_orange.png  
pear_orange.png  
banana_orange.png 

where in each case, the R, G, and B values for each pixel have been multiplied by 1, 0.5, and 0, respectively, and the alpha has been left alone. Is that possible?

William Jockusch

Posted 2011-05-14T00:43:44.523

Reputation: 2 913

Answers

3

Thanks Ignacio for the great hint. Based on it, here are the answers:

First of all, to convert a single file. Say we want to convert test.png to orangeTest.png, multiplying R, G, and B by 1.0, 0.5, and 0.0, respectively. Here is the command:

convert test.png xc:'rgb(255,127,0)' -fx 'u*v.p{0,0}' orangeTest.png

Now, for the mass conversion:

for i in *.png; 
   do convert "$i" xc:'rgb(255,127,0)' -fx 'u*v.p{0,0}' "${i%.*}_orange.png"; 
done

William Jockusch

Posted 2011-05-14T00:43:44.523

Reputation: 2 913

3

Ignacio Vazquez-Abrams

Posted 2011-05-14T00:43:44.523

Reputation: 100 516