7

I have a folder with a lot of xcf files which I want all to be converted to png files, at best via a one-liner from bash.

How can I achieve such a task?

k0pernikus
  • 14,853
  • 21
  • 58
  • 79
  • 2
    With [xcf2png](http://henning.makholm.net/software)... – jasonwryan Apr 14 '13 at 23:54
  • @jasonwryan Thanks, worked like a charm. – k0pernikus Apr 15 '13 at 00:01
  • 1
    You may want to give a try to `convert` tool from ImageMagick. Supports a lot of formats and operations, might be useful in future. – TNW Apr 15 '13 at 00:48
  • 1
    any of the `xcf2png` or ImageMagick answers won't work with the current XCF version (v. 12). This answer is currently (2022-07) effective: [image manipulation - How to convert XCF to PNG using GIMP from the command-line? - Stack Overflow](https://stackoverflow.com/questions/5794640/how-to-convert-xcf-to-png-using-gimp-from-the-command-line/5846727#5846727) – scruss Jul 30 '22 at 12:43

5 Answers5

8

One-liner from bash:

for i in *.xcf; do xcf2png -f $i -o $i.png; done

Alex Angas
  • 103
  • 4
k0pernikus
  • 14,853
  • 21
  • 58
  • 79
6

You can use GIMP Image editor and use Export to tool. Use Ctrl-Shift-E as shortcut.
Or you could use convert from imagemagick:

convert filename.xcf filename.png

You could also use xcftools (sudo apt-get install xcftools), which has a utility called xcf2png that does this job perfectly.

xcf2png image.xcf -o image.png
don_crissti
  • 79,330
  • 30
  • 216
  • 245
tusharmakkar08
  • 1,805
  • 1
  • 22
  • 23
2

same of @k0pernikus, but remove xcf extension from output filename

for i in *.xcf; do xcf2png -f $i -o "${i%.*}.png"; done

1

My one-liner using convert from imagemagik:

for i in Amplicon*.xcf; do convert $i ${i/xcf/png}; done

I had to keep my 'Amplicon' name because otherwise, it finds hidden xcf files in the directory and exports all the layers as individual PNGs haha. But it works! And the variant not using a loop (and could be parallelized)

find . -name "Amplicon*xcf" | xargs -I {} convert {} {}.png

But... I coudn't remove the '.xcf" from the filename. Still works!

J. Auger
  • 11
  • 1
1

Based on J. Auger's solution:

find . -name "Amplicon*xcf" | parallel convert {} {.}.png
Ole Tange
  • 33,591
  • 31
  • 102
  • 198