As you only need single-color transparency, you can use this code:
$img = imagecreatefromstring($your_image); //or whatever loading function you need
$white = imagecolorallocate($img, 255, 255, 255);
imagecolortransparent($img, $white);
imagepng($img, $output_file_name);
This is the simplest way that define white with imagecolortransparent().
I hope this helps.