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):

Becomes:

Using:

<?php

$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");

$im->readImage($png_file);
$color = 'blue';
$im->borderImage( $color, 1,1);
$im->readImage($png_file);
$im->borderImage( $color, 1,1);
$im->setImageFormat("png");

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

$im->readImage($tiled_file);
$im->borderImage( $color, 1,1);
$im->readImage($tiled_file);
$im->borderImage( $color, 1,1);
$im->resetIterator();

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

# $im->setImageFileName($output);
#combined->setImageCompressionQuality(100);

?>

 

0 Comments

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…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...