Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. images = [Image.open(filename).resize((300,300)) for filename in existing_images_df['impath']]
  2.  
  3. image_width, image_height = images[0].size
  4.  
  5. one_square_size = int(np.ceil(np.sqrt(len(images))))
  6. master_width = (image_width * one_square_size)
  7. master_height = image_height * one_square_size
  8.  
  9. master = Image.new(
  10. mode='RGBA',
  11. size=(master_width, master_height),
  12. color=(0,0,0,0)) # fully transparent
  13.  
  14. for count, image in enumerate(images):
  15. div, mod = divmod(count,one_square_size)
  16. h_loc = image_width*div
  17. w_loc = image_width*mod
  18. master.paste(image,(w_loc,h_loc))
  19.  
  20. master.convert("RGB").save('sprite.jpg', transparency=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement