Advertisement
mogra

Untitled

Jun 20th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. with BytesIO(b64decode(sku['image'])) as in_file,\
  2.      BytesIO() as raw_file,\
  3.      BytesIO() as out_file:
  4.     uu.decode(in_file=in_file, out_file=raw_file)
  5.     editor = Image.open(raw_file)
  6.  
  7.     MAX_SIZE = 4472
  8.     width,height = editor.size
  9.     original_size = max(width, height)
  10.     is_landscape = width > height
  11.     if original_size >= MAX_SIZE:
  12.         if is_landscape:
  13.             resized_width = MAX_SIZE
  14.             resized_height = int(round((MAX_SIZE/float(width))*height))
  15.         else:
  16.             resized_height = MAX_SIZE
  17.             resized_width = int(rount((MAX_SIZE/float(height))*width))
  18.         editor = editor.resize((resized_width, resized_height), Image.LANCZOS)
  19.  
  20.     editor.save(out_file, format='PNG')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement