SHARE
TWEET

photobooth

schoolpiclub Apr 21st, 2014 1,063 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import picamera
  2. from time import sleep
  3. import pygame
  4. import random
  5.  
  6. WIDTH=800
  7. HEIGHT=600
  8. FONTSIZE=50
  9.  
  10. def quote():
  11.     options = ["Strange person",
  12.                "You should have smiled",
  13.                "you will break the camera",
  14.                "you need a hair cut",
  15.                "You should try SnapChat",
  16.                "Are you a model?",
  17.                "You've grown an inch",
  18.                "Have you shrunk?"
  19.                ]
  20.     return random.choice(options)
  21.  
  22. # INIT CAMERA
  23. camera = picamera.PiCamera()
  24. camera.vflip = False
  25. camera.hflip = False
  26. camera.brightness = 60
  27.  
  28. # BUILD A SCREEN
  29. pygame.init()
  30. screen = pygame.display.set_mode((WIDTH,HEIGHT))
  31. black = pygame.Color(0, 0, 0)
  32. textcol = pygame.Color(255, 255, 0)
  33. screen.fill(black)
  34. n=0
  35.  
  36. while True:
  37.     # TAKE A PHOTO
  38.     name="image"+str(n)+".jpeg"
  39.     n+=1
  40.     camera.start_preview()
  41.     sleep(0.5)
  42.     camera.capture(name, format='jpeg', resize=(WIDTH,HEIGHT))
  43.     screen.fill(black)
  44.     pygame.display.update()    
  45.     camera.stop_preview()
  46.  
  47.     #READ IMAGE AND PUT ON SCREEN
  48.     img = pygame.image.load(name)
  49.     screen.blit(img, (0, 0))
  50.  
  51.     #OVERLAY CAPTIONS AS TEXT
  52.     text = quote()
  53.     font = pygame.font.Font('freesansbold.ttf', FONTSIZE)
  54.     font_surf = font.render(text, True, textcol)
  55.     font_rect = font_surf.get_rect()
  56.     font_rect.left = 100
  57.     font_rect.top = 100
  58.     screen.blit(font_surf, font_rect)
  59.     pygame.display.update()
  60.  
  61.     # WAIT A BIT
  62.     sleep(3)
  63.  
  64. # CLOSE CLEANLY AND EXIT
  65. pygame.quit()
RAW Paste Data
Top