Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/opb_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'/set/open', 'open_set',
'/set/close', 'close_set',
'/photo', 'save_photo',
'/set/print', 'print_set',
'/favicon.ico', 'favicon_serve'
)

Expand All @@ -52,6 +53,7 @@

theme_render = None
set_id = False
set_photos = []

# Sets everything required for properly rendering a theme
def SetTheme ( theme_name ):
Expand All @@ -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. """
Expand All @@ -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()
Expand All @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions app/static/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ OpenPhotoBooth = {
success: function ( data ) { Hook.call( 'core.postCloseSet', [ data ] ); }
}
);
}
},

}
printSet: function () {
jQuery.ajax(
{
url: "/set/print",
dataType: 'json',
cache: false,
async: false,
data: {}
}
);
}
}
Binary file added app/static/themes/default/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/static/themes/default/background.jpg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
((5, 155), (140,140))
((155, 155), (140,140))
((5, 300), (140,140))
((155, 300), (140,140))
1 change: 1 addition & 0 deletions app/static/themes/default/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!" );
Expand Down