-2

Input image size dimension (a,b)

output image size (c,d) where c> =k and d >= k

Example: input image(900,600) with minimum dimension k= 400

then output image should be (600,400)

Is there any function from PIL.Image to achieve this goal?

Ken Ho
  • 470
  • 2
  • 5
  • 18
  • http://stackoverflow.com/questions/1252218/pil-image-resize-not-resizing-the-picture OR http://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio OR http://stackoverflow.com/questions/24745857/python-pillow-how-to-scale-an-image – Lafexlos Nov 17 '16 at 14:53

1 Answers1

4

You can't use the usual "thumbnail", as it is designed for the more usual requirement of having a maximum dimension. Instead you can use "resize" method, after having computed the wanted size. Something like:

if image.width >= k and image.height >= k:
    if image.height < image.width:
        factor = float(k) / image.height
    else:
        factor = float(k) / image.width
    image.resize((image.width* factor, image.height * factor))
ch7kor
  • 184
  • 5