import click import numpy as np from PIL import Image from io import BytesIO from app.utils.cortex_utils import upload_bytes_to_cortex @click.command('') @click.option('-f', '--folder_id', 'opt_folder_id', required=True, help='ID of folder on Cortex') @click.pass_context def cli(ctx, opt_folder_id): """ Test uploading a BytesIO file to Cortex """ arr = get_gradation_3d(256, 256, (0, 0, 192), (255, 255, 64), (True, False, False)) arr = arr.astype(np.uint8) image = Image.fromarray(arr) fp = BytesIO() image.save(fp, format='png') upload_bytes_to_cortex(opt_folder_id, "test.png", fp, "image/png") def get_gradation_2d(start, stop, width, height, is_horizontal): if is_horizontal: return np.tile(np.linspace(start, stop, width), (height, 1)) else: return np.tile(np.linspace(start, stop, height), (width, 1)).T def get_gradation_3d(width, height, start_list, stop_list, is_horizontal_list): result = np.zeros((height, width, len(start_list)), dtype=np.float) for i, (start, stop, is_horizontal) in enumerate(zip(start_list, stop_list, is_horizontal_list)): result[:, :, i] = get_gradation_2d(start, stop, width, height, is_horizontal) return result