Created
April 22, 2023 05:17
-
-
Save omamkaz/5371bef180d5126fa0ab118acfc8911e to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python3 | |
from PIL import Image | |
import os.path | |
import sys | |
def resize_img(path: str, w: int, h: int) -> str: | |
image = Image.open(path) | |
new_image = image.resize((int(w), int(h))) | |
filename = os.path.basename(path).split(".", 1) | |
save_path = os.path.join(os.path.dirname(path), f"{filename[0]}_copied.{filename[-1]}") | |
new_image.save(save_path, optimize = True) | |
return save_path | |
def main() -> None: | |
""" | |
python3 resize_img.py width height path/to/image | |
""" | |
w, h, img = sys.argv[1:] | |
print(f"Resize '{img}' to ({w}x{h})...") | |
save_path = resize_img(img, w, h) | |
print(f"Done '{save_path}'.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment