title: How to use  PIL (Python Image Library)  rotate image and let black background to be transparency
body: <p>I want to rotate a gray "test" image and paste it onto a blue background image. Now I just can remove the black color after rotate my gray "test" image, but their is now a white color section. How can I use Python to change the "white" color section to blue?</p>
  
  <p>Here is my code, can someone help me? I'd appreciate it.</p>
  
  <pre><code>dst_im = Image.new("RGBA", (196,283), "blue" )
  im = src_im.convert('RGBA')
  rot = im.rotate( angle, expand=1 ).resize(size)
  f = Image.new( 'RGBA', rot.size, (255,)*4 )
  im2 = Image.composite( rot, f, rot )
  im2.convert(src_im.mode)
  im2_width, im2_height = im2.size
  cut_box = (0, 0, im2_width, im2_height )
  paste_box = ( left, top, im2_width+left, im2_height+top )
  region = im2.crop( cut_box )
  dst_im.paste( region, paste_box )
  dst_im.save("test.gif")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/oZoHR.gif" alt="enter image description here"></p>