title: Pillow crop images keeping the ratio having a max width and max height
body: <p>I need to crop something using Pillow, by keeping the ratio, and max_height or max_width.</p>
  
  <p>Some images can have a bigger width or a bigger height. </p>
  
  <p>I tried:</p>
  
  <pre><code>        image_clone = image.copy()
          width_percent = (size['width'] / float(image_clone.size[0]))
          height = int((float(image_clone.size[1]) * float(width_percent)))
          image_clone.thumbnail((size['width'], height), Image.LANCZOS)
  </code></pre>
  
  <p>Doesn't work well for images that have a bigger width because the height will be small, and the image not very visible.</p>