Friday, April 13, 2018

batch processing - How to convert a high number of PNG images to JPG forcing the background color?


I have around 200 hundred PNG small images and I would like to convert all of them into JPG with a black background.


I usually do these kind of batch work with FastStone Image Viewer but there are no option for background color.


Can you suggest me a method and a program that I can use to achieve that result?



Answer



Using ImageMagick's command line tools, you could do:


$ composite -compose Dst_Over -tile pattern:GRAY0 image.png image.jpg


Which



  1. Uses pre-generated pattern (GRAY0) that is solid black

  2. Puts the pattern behind (-compose Dst_Over) your png-file image.png

  3. Tiles the pattern (-tile) so it will fill the whole canvas

  4. Intelligently saves the composite image as JPG (IM recognises the needed conversion from image.jpg's extension)


Now, the aforementioned command can only do one composite image at a time, but you could hook to and loop it with other command line tools—be it Windows' command line, bash or anything else. (Looking at your profile, you might be most interested in Windows' tools.)


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...