title: PIL: overlaying images with different dimensions and aspect ratios
body: <p>I've been attempting to overlay two images in python to match coordinates, the top left and bottom right corners have the same coordinates and their aspects are almost identical bar a few pixels. Although they are different resolutions.</p>
  
  <p>Using PIL I have been able to overlay the images, though after overlaying them the image output is square but the resolution is that of the background image, the foreground image is also re-sized incorrectly (As far as I can see). I must be doing something wrong.</p>
  
  <pre><code>import Image
  from PIL import Image
  
  #load images
  background = Image.open('ndvi.png')
  foreground = Image.open('out.png')
  
  #resizing
  foreground.thumbnail((643,597),Image.ANTIALIAS)
  #overlay
  background.paste(foreground, (0, 0), foreground)
  #save
  background.save("overlay.png")
  #display
  background.show()
  </code></pre>
  
  <p>When dropping the images into something horrible like powerpoint the image aspects are almost identical. I've included an example image, the image on the left is my by hand overlay and the image on the right is the output from python. The background at some point in the code is squashed vertically, also affecting the overlay. I'd like to be able to do this in python and make it correctly look like the left hand image.</p>
  
  <p><img src="https://i.stack.imgur.com/yyLKQ.png" alt="enter image description here"></p>