title: How do I make the background of an image, that is pasted on top of another image, transparent in pillow?
body: <p>I'm making a chess bot which will run in a chat program reacting and moving pieces according to commands from users. As such, I am trying to make it paste png images of chess pieces on top of a png background image of a chessboard by using the python package pillow.</p>
  <p>In any other software, the chess pieces have transparent backgrounds and whatever is behind them show through but when I paste it on top of the chessboard using pillow the chess-piece gets a grey background which does not match the tile on the chessboard.</p>
  <p>Is there a way in which I can paste the chess-piece image on top of my chessboard background without the added grey background colour of the chess-piece? Or is there an alternative way of doing this in python which will give the desired result?</p>
  <p>I'm not done with the bot and the game logic but as an example, I have included some code illustrating how I've pasted one image on top of the other one below:</p>
  <pre><code>from PIL import Image
  
  board = Image.open('assets/chessboard.png')
  w_pawn = Image.open('assets/w_pawn_png_shadow_128px.png')
  
  a_eight = (102, 30, 210, 158)  # Left, top, right and bottom coordinates of where the piece is pasted onto the board
  
  battle_board = board.copy()
  battle_board.paste(w_pawn, a_eight)
  battle_board.show()
  </code></pre>
  <p>Just to quickly show what the output looks like I've included a screenshot of what a pawn looks like when it's pasted onto the board:</p>
  <p><a href="https://i.stack.imgur.com/aY3Yh.png" rel="nofollow noreferrer">A white pawn in A8 with faulty background colour</a></p>
  <p><a href="https://i.stack.imgur.com/mRdTa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mRdTa.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/yE4EK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yE4EK.png" alt="Chessboard" /></a></p>
  <p><a href="https://i.stack.imgur.com/44wZV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/44wZV.png" alt="white pawn" /></a></p>