Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with BytesIO(b64decode(sku['image'])) as in_file,\
- BytesIO() as raw_file,\
- BytesIO() as out_file:
- uu.decode(in_file=in_file, out_file=raw_file)
- editor = Image.open(raw_file)
- MAX_SIZE = 4472
- width,height = editor.size
- original_size = max(width, height)
- is_landscape = width > height
- if original_size >= MAX_SIZE:
- if is_landscape:
- resized_width = MAX_SIZE
- resized_height = int(round((MAX_SIZE/float(width))*height))
- else:
- resized_height = MAX_SIZE
- resized_width = int(rount((MAX_SIZE/float(height))*width))
- editor = editor.resize((resized_width, resized_height), Image.LANCZOS)
- editor.save(out_file, format='PNG')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement