Created
September 15, 2017 02:23
-
-
Save junmakii/72d42411492d5eff8031d122d15f9755 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """A image utility function to keep image aspect ratio. | |
| """ | |
| def get_size(im_size, size): | |
| """ | |
| :rtype: (int, int) | |
| >>> get_size((360, 100), (360, 180)) | |
| (648, 180) | |
| >>> get_size((100, 360), (360, 180)) | |
| (360, 1296) | |
| >>> get_size((512, 512), (640, 360)) | |
| (640, 640) | |
| """ | |
| if im_size[0] == im_size[1]: | |
| return (max(size), max(size)) | |
| elif im_size[0] > im_size[1]: | |
| width = size[1] * im_size[0] / im_size[1] | |
| return (width, size[1]) | |
| else: | |
| height = size[0] * im_size[1] / im_size[0] | |
| return (size[0], height) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment