def process(filename, w, h, output=None): if output is None: output = filename # output = filename + '-toaster.miff' scratch = filename + 'scratch.miff' # colortone # scratch = colortone(filename, '#330000', 100, 0, output=scratch) #scratch = colortone(filename, '#220000', 100, 0, output=scratch) scratch = colortone(filename, '#110000', 105, 0, output=scratch) brightness = Config.get('postprocessing', 'brightness') # contrast cmd = 'convert {} -modulate {},105,100 {}'.format( brightness, scratch, scratch ) execute(cmd) # vignette kungfu #scratch = vignette(scratch, w, h, 'none', 'LavenderBlush3') #scratch = vignette(scratch, w, h, '#FFD6C2', 'none') #scratch = vignette(scratch, w, h, '#E3C2B8', 'none') scratch = vignette(scratch, w, h, '#b3a298', 'none') execute('convert {} {}'.format(scratch, output)) os.unlink(scratch) return output
def capture(self): def shutter(result=None): d = self.camera.capture_image() return d interval = Config.getint('camera', 'countdown-interval') c = task.LoopingCall(bell0.play) d = c.start(interval) d = d.addCallback(shutter) task.deferLater(reactor, 3 * interval, c.stop) return d
def new(): import time # turn on all the relays on the arduino # the lights are wired on NC, so this turns lights off def lights_out(): arduino.sendCommand(0x81, 0) arduino.sendCommand(0x81, 1) arduino.sendCommand(0x81, 2) arduino.sendCommand(0x81, 3) logger.debug('starting photo booth service') session = Session() # preview frame producer logger.debug('starting camera preview service') preview_port = 23453 factory = protocol.Factory() factory.protocol = session.camera.create_producer reactor.listenTCP(preview_port, factory) # get the arduino going logger.debug('starting arduino') arduino = Arduino(session) try: s = SerialPort(arduino, Config.get('arduino', 'port'), reactor, baudrate=Config.getint('arduino', 'baudrate')) except serial.serialutil.SerialException: raise # give arduino a couple seconds to be ready to accept data time.sleep(5) reactor.callWhenRunning(lights_out) # arduino servo tilt server logger.debug('starting tilt command listener') reactor.listenTCP(Config.getint('arduino', 'tcp-port'), ServoServiceFactory(arduino)) return reactor
def __init__(self): logger.debug('building new session...') self.template = configparser.ConfigParser() self.template.read(template_path) self.camera = None self.plugins = dict((get_class(p), p) for p in getPlugins(ipyrikura.IPyrikuraPlugin)) for name in self.plugins.keys(): logger.debug("loaded plugin %s", name) self.camera = self.plugins['ShutterCamera'].new( re.compile(Config.get('camera', 'name')))
import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("purikura.kiosk-loader") DEFAULT_VKEYBOARD_LAYOUT = 'email' # because i hate typing jpath = os.path.join # set keyboard behaviour to be a little like ios Config.set('kivy', 'keyboard_mode', 'dock') Config.set('kivy', 'keyboard_layout', DEFAULT_VKEYBOARD_LAYOUT) # set the display up Config.set('graphics', 'fullscreen', pkConfig.get('display', 'fullscreen')) Config.set('graphics', 'width', pkConfig.getint('display', 'width')) Config.set('graphics', 'height', pkConfig.getint('display', 'height')) # the display/touch input i use needs some love Config.set('postproc', 'retain_time', pkConfig.getint('kiosk', 'touch-retain-time')) Config.set('postproc', 'retain_distance', pkConfig.getint('kiosk', 'touch-retain-distance')) # paths all_images_path = pkConfig.get('paths', 'images') event_name = pkConfig.get('event', 'name') event_images_path = jpath(all_images_path, event_name)
def load(): global sounds, images, music, loaded if loaded: logger.debug('want to load resources, but already have') return logger.debug('loading resources...') sounds = dict() images = dict() music = dict() if Config.has_section('sound-files'): vol = Config.getint('sound', 'sound-volume') / 100. for name, filename in Config.items('sound-files'): path = jpath(resource_path, 'sounds', filename) logger.info("loading %s", path) sound = pygame.mixer.Sound(path) sound.set_volume(vol) sounds[name] = sound if Config.has_section('image-files'): for name, filename in Config.items('image-files'): path = jpath(resource_path, 'images', filename) logger.info("loading %s", path) # image = pygame.image.load(path) #images[name] = image
def start(self, result=None, arduino=None): global in_session logger.debug('start new session') if in_session: defer.returnValue(None) in_session = True if arduino: arduino.sendCommand(0x82, 0) arduino.sendCommand(0x82, 1) arduino.sendCommand(0x82, 2) arduino.sendCommand(0x82, 3) countdown_delay = Config.getint('camera', 'countdown-delay') needed_captures = template.needed_captures(self.template) captures = 0 errors = 0 # PLUGINS p = self.plugins fc0 = p['FileCopy'].new(originals_path) fc1 = p['FileCopy'].new(composites_path) #fc3 = p['FileCopy'].new(thumbs_path) #fc4 = p['FileCopy'].new(details_path) #fc5 = p['FileCopy'].new(template_path) spool = p['FileCopy'].new(shared_path) #th0 = p['ImageThumb'].new(size='256x256', destination='thumbnail.png') #th1 = p['ImageThumb'].new(size='1024x1024', destination='thumbnail.png') cm = p['Composer'].new(self.template) #fd0 = p['FileDelete'].new() #fd1 = p['FileDelete'].new() filenames = list() while captures < needed_captures and errors < 3: try: filename = yield task.deferLater(reactor, countdown_delay, self.capture) except: traceback.print_exc(file=sys.stdout) errors += 1 logger.debug('failed capture %s/3', errors) task.deferLater(reactor, 0, error.play) task.deferLater(reactor, .15, error.play) task.deferLater(reactor, .30, error.play) continue captures += 1 errors = 0 logger.debug('successful capture (%s/%s)', captures, needed_captures) if captures < needed_captures: finished.play() else: bell1.play() # C A L L B A C K S fn = filename original = yield fc0.process(fn) filenames.append(original) #thumb = yield th0.process(original) #thumb = yield fc3.process(thumb) #detail = yield th1.process(original) #detail = yield fc4.process(detail) if arduino: arduino.sendCommand(0x81, 0) arduino.sendCommand(0x81, 1) arduino.sendCommand(0x81, 2) arduino.sendCommand(0x81, 3) # composite d = cm.process(filenames.pop(0)) d.addCallback(fc1.process) if Config.getboolean('kiosk', 'print'): d.addCallback(spool.process) for fn in filenames: cm.process(fn) in_session = False logger.debug('finished the session')
import re from pyrikura import ipyrikura from pyrikura import resources from pyrikura import template from pyrikura.config import Config import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("purikura.booth") # because i hate typing jpath = os.path.join # paths app_root_path = Config.get('paths', 'root') app_config_path = jpath(app_root_path, 'config') app_resources_path = jpath(app_root_path, 'resources') app_sounds_path = jpath(app_resources_path, 'sounds') app_images_path = jpath(app_resources_path, 'images') all_templates_path = jpath(app_resources_path, 'templates') all_images_path = Config.get('paths', 'images') shared_path = Config.get('paths', 'shared') plugins_path = Config.get('paths', 'plugins') # event paths event_name = Config.get('event', 'name') template_path = jpath(all_templates_path, Config.get('event', 'template')) event_images_path = jpath(all_images_path, event_name) thumbs_path = jpath(event_images_path, 'thumbnails') details_path = jpath(event_images_path, 'detail')