in un commento dice

The problem with the GIF type is that those with transparent backgrounds need to be treated differently to those without. When I don't detect GIF transparency, I either end up with all transparent GIF's having black backgrounds

che mi sembra sia esattamente il problema che capita a te.

prova a vedere se la funzione che inizia con questo commento risolve il tuo problema.
I'm feeling particularly altruistic today, so here is the code to accompany the text I submitted about a script that 'intelligently' detects if an uploaded GIF has transparency or not, and creates a thumbnail accordingly: