diff --git a/app/opb_web.py b/app/opb_web.py index ac5c9eb..0c4135d 100644 --- a/app/opb_web.py +++ b/app/opb_web.py @@ -34,6 +34,7 @@ '/set/open', 'open_set', '/set/close', 'close_set', '/photo', 'save_photo', + '/set/print', 'print_set', '/favicon.ico', 'favicon_serve' ) @@ -52,6 +53,7 @@ theme_render = None set_id = False +set_photos = [] # Sets everything required for properly rendering a theme def SetTheme ( theme_name ): @@ -70,6 +72,7 @@ def GET( self ): class save_photo: def POST( self ): global set_id + global set_photos web.header( 'Content-type', 'application/json; charset=utf-8' ) """ Save the photo data, thumbnail it and move on. """ @@ -80,6 +83,7 @@ def POST( self ): else: filename = "NOSET_%s.jpg" % ( int( time.time() ) ) + set_photos.append(filename) fullsize = open( './static/photos/' + filename, 'wb' ) fullsize.write( base64.standard_b64decode( i.image ) ) fullsize.close() @@ -90,16 +94,50 @@ def POST( self ): im.save( './static/thumbs/' + filename, "JPEG" ) return '{ "saved": true, "thumbnail": "%s" }' % ( filename ) +class print_set: + def GET ( self ): + global set_photos + self.printout( self.construct_print( 'background.jpg' ) ) + + def construct_print ( self, backgroundfile ): + global set_id + global set_photos + background = Image.open( "./" + opb['theme_path'] + '/%s' % ( backgroundfile ) ) + placement = open( "./" + opb['theme_path'] + '/%s.cfg' % ( backgroundfile ) ) + for count, line in enumerate( placement ): + pos, size = eval( line ) + i1 = set_photos[ (count % len( set_photos ) )] + background.paste( Image.open('./static/photos/' + i1).resize(size), pos ) + if False != set_id: + outfile = "./static/photos/%s_%s_print.jpg" % ( set_id, int( time.time() ) ) + else: + outfile = "./static/photos/NOSET_%s_print.jpg" % ( int( time.time() ) ) + print_output = background.save( outfile ) + return outfile + + def printout( self , filename ): + try: + import win32api + win32api.ShellExecute ( 0, "print", filename, None, ".", 0 ) + except ImportError: + # Probably not Win, try printing via lpr + import subprocess + subprocess.Popen(['lpr', filename]) + class open_set: def GET ( self ): global set_id + global set_photos set_id = "%s" % int( time.time() ) + set_photos = [] return '{ "set": "%s" }' % set_id class close_set: def GET ( self ): global set_id + global set_photos set_id = False + set_photos = [] return '{ "set": false }' class favicon_serve: diff --git a/app/static/core/core.js b/app/static/core/core.js index b91f477..0a09655 100644 --- a/app/static/core/core.js +++ b/app/static/core/core.js @@ -78,6 +78,17 @@ OpenPhotoBooth = { success: function ( data ) { Hook.call( 'core.postCloseSet', [ data ] ); } } ); - } + }, -} \ No newline at end of file + printSet: function () { + jQuery.ajax( + { + url: "/set/print", + dataType: 'json', + cache: false, + async: false, + data: {} + } + ); + } +} diff --git a/app/static/themes/default/background.jpg b/app/static/themes/default/background.jpg new file mode 100644 index 0000000..47f6b3e Binary files /dev/null and b/app/static/themes/default/background.jpg differ diff --git a/app/static/themes/default/background.jpg.cfg b/app/static/themes/default/background.jpg.cfg new file mode 100644 index 0000000..80affa5 --- /dev/null +++ b/app/static/themes/default/background.jpg.cfg @@ -0,0 +1,4 @@ +((5, 155), (140,140)) +((155, 155), (140,140)) +((5, 300), (140,140)) +((155, 300), (140,140)) diff --git a/app/static/themes/default/config.js b/app/static/themes/default/config.js index 44461f0..12864d9 100644 --- a/app/static/themes/default/config.js +++ b/app/static/themes/default/config.js @@ -32,6 +32,7 @@ OPBConfig = { ++OPBSkin.captured; $( '#photo' + OPBSkin.captured ).attr( 'src', OPBThumbPath + json.thumbnail ); if( OPBSkin.captured >= 4 ) { + OpenPhotoBooth.printSet(); OpenPhotoBooth.closeSet(); OpenPhotoBooth.openSet(); $( "#countdown" ).html( "All Done! Thanks!" );