Created
April 5, 2020 03:07
-
-
Save nick3499/ddc0cfb2c6fa08bcbb89bd6d3183533e to your computer and use it in GitHub Desktop.
Comparison for Image Resize: Python3, os.chdir(), os.listdir(), PIL.Image()
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
| #! /bin/python3 | |
| '''`gm_resize` module contains `gm_resize()` method for resizing an image.''' | |
| from os import chdir | |
| from os import listdir | |
| from PIL import Image | |
| def gm_resize(): | |
| '''A dimensional comparison is used to determine whether an image should \ | |
| be resized based on image width or image height.''' | |
| chdir('/usr/local/lib/scifi_wallpaper/img') | |
| imgs = sorted(listdir('.')) | |
| for img in imgs: | |
| img_obj = Image.open(f'/usr/local/lib/scifi_wallpaper/img/{img}') | |
| print(f'\x1b[1;34mName\x1b[0m: {img} {img_obj.size}') | |
| print(f'\x1b[1;33mWidth-based\x1b[0m: \ | |
| {((1600.0 / img_obj.width) * img_obj.width > 1600.0)} \ | |
| | \x1b[1;32mgm mogrify -resize 1600x\x1b[0m foo.jpg') | |
| print(f'\x1b[1;33mHeight-based\x1b[0m: \ | |
| {((900.0 / img_obj.height) * img_obj.height > 900.0)} \ | |
| | \x1b[1;32mgm mogrify -resize x900\x1b[0m foo.jpg') | |
| print(f'\x1b[1;35m--------------------------------------------\x1b[0m') | |
| if __name__ == '__main__': | |
| gm_resize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment