Created
October 15, 2019 17:47
-
-
Save mitchtabian/498e13c0602a8b3b395d8147dd6f2fb1 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
import cv2 | |
import os | |
def is_image_aspect_ratio_valid(img_url): | |
img = cv2.imread(img_url) | |
dimensions = tuple(img.shape[1::-1]) # gives: (width, height) | |
print("dimensions: " + str(dimensions)) | |
aspect_ratio = dimensions[0] / dimensions[1] # divide w / h | |
print("aspect_ratio: " + str(aspect_ratio)) | |
if aspect_ratio < 1: | |
return False | |
return True | |
def is_image_size_valid(img_url, mb_limit): | |
image_size = os.path.getsize(img_url) | |
print("image size: " + str(image_size)) | |
if image_size > mb_limit: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment