Python PIL: How can set to a png image the background to white?
<p>I have a png image with transparent background and I want to resize it to another image, but with white background instead of transparent one. 
How can I do that with PIL?</p>

<p><strong>Here is my code:</strong></p>

<pre><code>basewidth = 200
img = Image.open("old.png")
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)hsize = int((float(img.size[1]) * float(wpercent)))
img.save("new.png")
</code></pre>

<p><strong>Update</strong></p>

<pre><code>import numpy as np
import PIL
from PIL import Image


basewidth = 200
img = Image.open("old.png")
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
data = np.array(img)

alpha1 = 0 # Original value
r2, g2, b2, alpha2 = 255, 255, 255,255 # Value that we want to replace it with

red, green, blue,alpha = data[:,:,0], data[:,:,1], data[:,:,2], data[:,:,3]
mask = (alpha==alpha1)
data[:,:,:4][mask] = [r2, g2, b2, alpha2]


img = Image.fromarray(data)
img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
img.save('new.png')
</code></pre>

<p>Here is the code provided by @khakishoiab and @Chachmu
Thanks guys!</p>

<pre><code>   import Image
f = Image.open('old.png')


     from resizeimage import resizeimage
        alpha1 = 0 # Original value
    r2, g2, b2, alpha2 = 255, 255, 255,255 # Value that we want to replace it with

    red, green, blue,alpha = data[:,:,0], data[:,:,1], data[:,:,2], data[:,:,3]
    mask = (alpha==alpha1)
    data[:,:,:3][mask] = [r2, g2, b2, alpha2]



 data = np.array(f)
    f = Image.fromarray(data)
    f = f.resize((basewidth,hsize), PIL.Image.ANTIALIAS)

                f.save('modified.png', image.format)
</code></pre>

python python-imaging-library