Created
March 15, 2022 21:29
-
-
Save catter1/ce647a39818800b4f563fae20d01ffd3 to your computer and use it in GitHub Desktop.
Image Standardizer
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
import sys | |
from wand.image import Image | |
sys.argv.pop(0) | |
if len(sys.argv) < 1: | |
print("Please provide at least 1 image file path as an argument.") | |
sys.exit() | |
HEIGHT = 1008 | |
WIDTH = 1792 | |
RATIO = 0.5625 | |
for imgpath in sys.argv: | |
image = Image(filename=imgpath) | |
#print(image.width, image.height, sep="x") | |
#print("Ratio:", image.height/image.width) | |
if RATIO >= image.height/image.width : | |
rswidth = (int)((HEIGHT * image.width) / image.height) | |
image.sample(rswidth, HEIGHT) | |
if image.width != WIDTH: | |
image.crop(width=WIDTH, height=HEIGHT, gravity="center") | |
else: | |
rsheight = (int)((WIDTH * image.height) / image.width) | |
image.sample(WIDTH, rsheight) | |
if image.height != HEIGHT: | |
image.crop(width=WIDTH, height=HEIGHT, gravity="center") | |
#print(image.width, image.height, sep="x") | |
#print("Ratio:", image.height/image.width) | |
image.save(filename=imgpath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment