Convert XCF to PNG using xcftools and PHP ImageMagick Binding

An sample image (originally in…

Login

Blog History

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.