The backwards compatibility example does not preserve transparency. You must first wipe out the default black background on the new image:
<?php
if (!function_exists('imagepalettetotruecolor')) {
function imagepalettetotruecolor(&$src) {
if (imageistruecolor($src)) {
return true;
}
$dst = imagecreatetruecolor(imagesx($src), imagesy($src));
imagealphablending($dst, false);$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);imagefilledrectangle($dst, 0, 0, $imagesx($src), imagesy($src), $transparent);imagealphablending($dst, true);imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src));
imagedestroy($src);
$src = $dst;
return true;
}
}
?>