Skip to content

Instantly share code, notes, and snippets.

@mitchtabian
Created October 15, 2019 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchtabian/498e13c0602a8b3b395d8147dd6f2fb1 to your computer and use it in GitHub Desktop.
Save mitchtabian/498e13c0602a8b3b395d8147dd6f2fb1 to your computer and use it in GitHub Desktop.
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