What are the potential pitfalls of using imagecopyresampled versus imagecopyresized when dealing with transparent GIFs?

When dealing with transparent GIFs, using imagecopyresampled can cause the transparency to be lost or altered due to the resampling process. To maintain the transparency of GIFs, it is recommended to use imagecopyresized instead, as it preserves the transparency of the image.

// Load the original transparent GIF image
$source = imagecreatefromgif('original.gif');

// Create a new image with the desired dimensions
$destination = imagecreatetruecolor($newWidth, $newHeight);

// Preserve transparency of the original image
imagecolortransparent($destination, imagecolorallocatealpha($destination, 0, 0, 0, 127));
imagealphablending($destination, false);
imagesavealpha($destination, true);

// Copy and resize the original image to the new image
imagecopyresized($destination, $source, 0, 0, 0, 0, $newWidth, $newHeight, imagesx($source), imagesy($source));

// Output the resized image
imagegif($destination, 'resized.gif');

// Free up memory
imagedestroy($source);
imagedestroy($destination);