views:

172

answers:

2

How to do that with GD?

+3  A: 

Create a new truecolor image resource (t) with the same dimensions as the source image (s) and then copy (s) to (t).

e.g. (without error handling):

$imgSource = imagecreatefromgif('xyz.gif');
$width = imagesx($imgSource);
$height = imagesy($imgSource);
$imgTC = imagecreatetruecolor($width, $height);
imagecopy($imgTC, $imgSource, 0, 0, 0, 0, $width, $height);
// save or send $imgTC

You'll have both images in memory in the gd2 format (4 bytes per pixel? 5?), so you better check your memory_limit setting before trying this with larger images.

VolkerK
+1  A: 

All you need to do is use imagecreatetruecolor to create a new image and then imagecopy your palette-based image onto it.

Greg