def parse_image(file, guid): if file.startswith("http://") or file.startswith("https://"): response = requests.get(file) image = Image.open(BytesIO(response.content)) else: image = Image.open(file) iwidth, iheight = image.size f_format = get_extension(file) with connection.cursor() as cursor: cursor.execute( """ INSERT INTO image_metadata ( file_guid, width, height, file_format ) VALUES ( %s, %s, %s, %s ) """, [guid, iwidth, iheight, f_format]) return True