0

I would like to batch resize and convert to jpg a few png files. But some pixels are transparent, and some are half transparent; I would like the transparent ones to be white, and the half-transparent ones to be white half mixed with color.

I have two half solutions:

convert file.png -resize 1200x1200  -background white -flatten  file.jpg

which works well, but only for one file; so is there an easy way to batch the "convert" command? I want my files to keep their names, which are not numbered (img001.png, img002.png, etc.) but descriptive (room.png, horse.png, etc.)... Or:

mogrify -resize 1200x1200 -format jpg -background "#FFFFFF" *.png

which batches well, but the half-transparent pixels are full color, which is pretty ugly when a line is supposed to fade into alpha; is there a way to fix this?

Oli
  • 299,380
Fal
  • 65

1 Answers1

0

You could use a for loop:

for f in ./*.png; do convert "$f" -resize -background white -flatten "${f%.*}.jpg"; done

This will operate on every file with a name ending in .png in the current directory. Each go around on the loop, the matched filename is read into the variable $f; in order to massage this information into the output filename, the above command uses parameter substitution.

${var%Pattern} -- Remove from $var the shortest part of $Pattern that matches the back end of $var.

${var%%Pattern} -- Remove from $var the longest part of $Pattern that matches the back end of $var.

evilsoup
  • 4,625