Convert XCF to PNG using xcftools and PHP ImageMagick Binding

Written by James McDonald

September 25, 2012

An sample image (originally in GIMP xcf format):




$xcf2png = '/usr/bin/xcf2png';
$xcf_file = 'gimp_sample.xcf';
$jpg_file = 'gimp_sample.jpg';
$png_file = 'gimp_sample.png';
$tiled_file = 'gimp_tiled.png';

$cmd = $xcf2png . ' ' . $xcf_file . ' -o ' . $png_file;
echo $cmd . "\n";
# use php system() because xcf2png is 
# much better than Imagick at converting
# xcf's to png's
$last_line = system($cmd, $retval);
echo "Last Line " . $last_line . "Return value: " . $retval . "\n";
# create a new ImageMagick object
$im = new Imagick();

# $handle = fopen('gimp_sample.xcf', "r");

$color = 'blue';
$im->borderImage( $color, 1,1);
$im->borderImage( $color, 1,1);

$combined = $im->appendImages(false);
$combined->writeImages($tiled_file, true);

$im->borderImage( $color, 1,1);
$im->borderImage( $color, 1,1);

$combined = $im->appendImages(true);
$combined->writeImages($tiled_file, true);

# $im->setImageFileName($output);




Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...