AppEngine Images API Resize on width only and maintain aspect ratio
-
10-10-2019 - |
문제
A user can upload a picture to blobstore, which I would like to resize to have a maximum of only 500px in width. I don't want to specify the height since I want it to maintain the aspect ratio.
The resize() function of the images api seems to require the height as well. Is this true?
How do I get what I want?
해결책
The AppEngine API docs for the resize method say:
Resizes an image, scaling down or up to the given width and height. The resize transform preserves the aspect ratio of the image. If both the width and the height arguments are provided, the transform uses the dimension that results in a smaller image.
This sounds like exactly what you want. Just specify the width, and the height will be transformed into the appropriate value to maintain the aspect ratio of the original image.