import cv2 def image_to_thumbs(img): """Create thumbs from image""" height, width, channels = img.shape thumbs = {"original": img} sizes = [640, 320, 160] for size in sizes: if (width >= size): r = (size + 0.0) / width max_size = (size, int(height * r)) thumbs[str(size)] = cv2.resize(img, max_size, interpolation=cv2.INTER_AREA) return thumbs