Mi capitò lo stesso problema quando scrissi una classe per il ridimensionamento di immagini. Trovai del codice (non ricordo dove) che mi risolse il problema che le png e le gif trasparenti venivano ridimensionate con sfondo nero.
Ti posto il mio codice brutalmente, ovviamente andrà aggiustato per il tuo caso
Codice PHP:
$image_resized = imagecreatetruecolor($final_width, $final_height);
if (($this->image_type == IMAGETYPE_GIF) || ($this->image_type == IMAGETYPE_PNG) )
{
$trnprt_indx = imagecolortransparent($image);
// If we have a specific transparent color
if ($trnprt_indx >= 0)
{
// Get the original image's transparent color's RGB values
$trnprt_color = imagecolorsforindex($image, $trnprt_indx);
// Allocate the same color in the new image resource
$trnprt_indx = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($image_resized, 0, 0, $trnprt_indx);
// Set the background color for new image to transparent
imagecolortransparent($image_resized, $trnprt_indx);
}
// Always make a transparent background color for PNGs that don't have one allocated already
elseif ($this->image_type == IMAGETYPE_PNG)
{
// Turn off transparency blending (temporarily)
imagealphablending($image_resized, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
// Completely fill the background of the new image with allocated color.
imagefill($image_resized, 0, 0, $color);
// Restore transparency blending
imagesavealpha($image_resized, true);
}
}
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $this->width, $this->height);