title: Convert .XCF to .PNG using script-fu called from PHP
body: <p>I would like to convert a number of .XCF image to .PNG images within a PHP script. (Flattening layers, preserving transparency, and honouring the layer visibility setting).</p>
  
  <p>It seems that you can call the GIMP in command line mode and use its script-fu language to do this. I have found various answers to similar problems, however there is so much going on in the solutions that I can figure out how to run them properly and adapt them to PHP.</p>
  
  <p>Here's an example that I tried to use - its supposed to find all the .XCF files in a directory and convert them to PNGs.</p>
  
  <pre><code>        $execStg = ' "C:\Program Files\GIMP 2\bin\gimp-2.8.exe" -n -i -b - &lt;&lt;eof (let*="" (="" (file\'s="" (cadr="" (file-glob="" "*.xcf"="" 1)))="" (filename="" "")="" (image="" 0)="" (layer="" )="" (while="" (pair?="" file\'s)="" (set!="" image="" (car="" (gimp-file-load="" run-noninteractive="" file\'s))))="" layer="" (gimp-image-merge-visible-layers="" clip-to-image)))="" filename="" (string-append="" (substring="" 0="" (-="" (string-length="" file\'s))="" 4))="" ".png"))="" (gimp-file-save="" filename)="" (gimp-image-delete="" image)="" file\'s="" (cdr="" (gimp-quit="" eof&lt;="" pre=""&gt; ';
          exec($execStg, $results);
  </code></pre>
  
  <p><a href="http://www.gimptalk.com/index.php?/topic/46715-batch-convert-xcf-to-png/page__p__354668#entry354668" rel="nofollow">http://www.gimptalk.com/index.php?/topic/46715-batch-convert-xcf-to-png/page_<em>p</em>_354668#entry354668</a></p>
  
  <p>I couldnt get this to work (I also tried running the command in a DOS box).</p>
  
  <p>What I really want to do is adapt this script so I can specify a number of file names to be converted to pngs. Can anyone give me a hand adapting the above script (or provide something equivalent).</p>
  
  <p>(I would prefer if the entire script is contained in my PHP file rather than having other bits in other places such as in GIMP's plug-in folder.)</p>