works now but prints weird

This commit is contained in:
trav 2022-08-17 15:39:36 -04:00
parent 8e87c75c3a
commit f8fa50c223
3 changed files with 77 additions and 61 deletions

View File

@ -7,6 +7,7 @@ import optparse
import iterparse import iterparse
import traceback import traceback
import os, sys import os, sys
import json
import subprocess import subprocess
from tinydb import TinyDB, Query from tinydb import TinyDB, Query
@ -26,22 +27,25 @@ def main():
exit(1) exit(1)
def addToDB(pathToImage, pathToDB,composite):
def addFile(pathToImage, pathToDB, SSBidentify, composite): #init db
#init db
db = TinyDB(pathToDB) db = TinyDB(pathToDB)
#add to db #add to db
db.insert({'path': pathToImage, 'date': 4, 'ssb': SSBidentify, 'composite': composite}) db.insert({'path': pathToImage, 'date': 4, 'ssb': '-2', 'composite': composite})
print("all done, added to db") print("all done, added to db")
#print("heres the whole db") #print("heres the whole db")
#print(db.all()) #print(db.all())
def addToSSB(pathToImage, pathToDB, SSBidentify):
#unless you say don't post to ssb, post to ssb #unless you say don't post to ssb, post to ssb
if SSBidentify != -1: if SSBidentify != -1:
#SEND TO SSB! WOOOO #SEND TO SSB! WOOOO
try: try:
result = subprocess.call('./ssbpost.sh ' + pathToImage, shell=True) result = subprocess.Popen('./ssbpost.sh ' + pathToImage, shell=True, stdout=subprocess.PIPE, )
except: except:
print('traceback.format_exc():\n%s' % traceback.format_exc()) print('traceback.format_exc():\n%s' % traceback.format_exc())
exit() exit()
@ -49,12 +53,12 @@ def addFile(pathToImage, pathToDB, SSBidentify, composite):
# get the ssb json from the bash command we just ran # get the ssb json from the bash command we just ran
newssb=result.stdout.read() newssb=result.stdout.read()
print(newssb)
#convert string to object
json_object = json.loads(newssb)
# iterate through new ssb posts # get the key for the post we just made
for decoded in iterparse.parsy(newssb): key = json_object["key"]
# get the key for the post we just made
key = decoded['key']
return key return key

View File

@ -124,6 +124,13 @@ def get_concat_h(im1, im2):
dst.paste(im2, (im1.width, 0)) dst.paste(im2, (im1.width, 0))
return dst return dst
def get_concat_h_blank(im1, im2, color=(0, 0, 0)):
dst = Image.new('RGB', (im1.width + im2.width, max(im1.height, im2.height)), color)
dst.paste(im1, (0, 0))
dst.paste(im2, (im1.width, 0))
return dst
## MAIN LOOP ## ## MAIN LOOP ##
while True: while True:
# chill for a bit, keep track of how long we're chilling # chill for a bit, keep track of how long we're chilling
@ -228,7 +235,7 @@ while True:
except: except:
print('traceback.format_exc():\n%s' % traceback.format_exc()) print('traceback.format_exc():\n%s' % traceback.format_exc())
exit() exit()
#create half-size bmps for cycling through #create half-size bmps for cycling through
half1 = Image.open(jpgpath1) half1 = Image.open(jpgpath1)
half2 = Image.open(jpgpath2) half2 = Image.open(jpgpath2)
@ -243,11 +250,11 @@ while True:
half2.save(bmpath2) half2.save(bmpath2)
half3 = half3.convert("1") half3 = half3.convert("1")
half3.save(bmpath3) half3.save(bmpath3)
## CREATE screen image to display: ## CREATE screen image to display:
# create quarter sized bmps # create quarter sized bmps
im1 = Image.open(jpgpath1) im1 = Image.open(jpgpath1)
im2 = Image.open(jpgpath2) im2 = Image.open(jpgpath2)
@ -256,7 +263,7 @@ while True:
im1 = im1.resize(newsize) im1 = im1.resize(newsize)
im2 = im2.resize(newsize) im2 = im2.resize(newsize)
im3 = im3.resize(newsize) im3 = im3.resize(newsize)
#add quarter sized photos and instructions to the image to be rendered #add quarter sized photos and instructions to the image to be rendered
instructions = imagesPath + 'instructions.bmp' instructions = imagesPath + 'instructions.bmp'
im4 = Image.open(instructions) im4 = Image.open(instructions)
@ -264,8 +271,8 @@ while True:
Limage.paste(im2, (150,0)) Limage.paste(im2, (150,0))
Limage.paste(im3, (0,200)) Limage.paste(im3, (0,200))
Limage.paste(im4, (150,200)) Limage.paste(im4, (150,200))
#add the menu #add the menu
# draw = ImageDraw.Draw(Limage) # draw = ImageDraw.Draw(Limage)
# font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 10) # font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 10)
# draw.text((152, 200), 'press button 1 to:', font = font18, fill = 255) # draw.text((152, 200), 'press button 1 to:', font = font18, fill = 255)
@ -275,13 +282,13 @@ while True:
# draw.text((152, 280), 'button 3: retake', font = font18, fill = 255) # draw.text((152, 280), 'button 3: retake', font = font18, fill = 255)
# draw.text((152, 00), 'buttons 4 or 5:', font = font18, fill = 255) # draw.text((152, 00), 'buttons 4 or 5:', font = font18, fill = 255)
# draw.text((152, 640), 'exit photo mode', font = font18, fill = 255) # draw.text((152, 640), 'exit photo mode', font = font18, fill = 255)
# display the image # display the image
epd.init() epd.init()
epd.display(epd.getbuffer(Limage)) epd.display(epd.getbuffer(Limage))
#pulse LED while we wait for user to press something #pulse LED while we wait for user to press something
button_flag = "none" button_flag = "none"
while button_flag == "none": while button_flag == "none":
@ -296,46 +303,50 @@ while True:
#led to thinking mode #led to thinking mode
buttonshim.set_pixel(0x00, 0x00, 0xFF) buttonshim.set_pixel(0x00, 0x00, 0xFF)
# if we're printing, generate image to print # if we're printing, generate image to print
if button_flag == "button_1" or button_flag == "button_2" or button_flag == "button_3": if button_flag == "button_1" or button_flag == "button_2" or button_flag == "button_3":
#generate unique file_name #generate unique file_name
unique = uuid.uuid4() unique = uuid.uuid4()
unique = str(unique) unique = str(unique)
composite = imagesPath + unique + '.jpg' composite = imagesPath + unique + '.jpg'
# concatenate images and save concatenated image at composite (is filepath) # concatenate images and save concatenated image at composite (is filepath)
headerIsAt = imagesPath + 'header.jpg' headerIsAt = imagesPath + 'header.jpg'
header = Image.open(headerIsAt) header = Image.open(headerIsAt)
im1 = Image.open(jpgpath1) im1 = Image.open(jpgpath1)
im2 = Image.open(jpgpath2) im2 = Image.open(jpgpath2)
im3 = Image.open(jpgpath3) im3 = Image.open(jpgpath3)
get_concat_v(header, im1).save(composite) get_concat_v(header, im1).save(composite)
concaz = Image.open(composite) concaz = Image.open(composite)
get_concat_v(concaz, im2).save(composite) get_concat_v(concaz, im2).save(composite)
concaz = Image.open(composite) concaz = Image.open(composite)
get_concat_v(concaz, im3).save(composite) get_concat_v(concaz, im3).save(composite)
concaz = Image.open(composite) concaz = Image.open(composite)
#post to ssb and print #post to ssb and print
if button_flag == "button_1": if button_flag == "button_1":
button_flag == "null" button_flag == "null"
#add the photo to the db/ssb #add each photo to the db
key = addtoDB.addFile(bmpath,dbPath,0,composite) addtoDB.addToDB(bmpath1,dbPath,composite)
addtoDB.addToDB(bmpath2,dbPath,composite)
addtoDB.addToDB(bmpath3,dbPath,composite)
#add the photo strip to the ssb
key = addtoDB.addToSSB(composite,dbPath,0)
# Create qr code # Create qr code
#from https://ourcodeworld.com/articles/read/554/how-to-create-a-qr-code-image-or-svg-in-python #from https://ourcodeworld.com/articles/read/554/how-to-create-a-qr-code-image-or-svg-in-python
qr = qrcode.QRCode( qr = qrcode.QRCode(
version = 1, version = 1,
error_correction = qrcode.constants.ERROR_CORRECT_H, error_correction = qrcode.constants.ERROR_CORRECT_H,
box_size = 4, box_size = 5,
border = 1, border = 1,
) )
# Add data # Add data
@ -343,35 +354,36 @@ while True:
qr.make(fit=True) qr.make(fit=True)
# Create an image from the QR Code instance # Create an image from the QR Code instance
img = qr.make_image() img = qr.make_image()
whereToSaveQR = imagesPath + 'QR.jpg'
img.save(whereToSaveQR)
# concatenate QR instructions with QR # concatenate QR instructions with QR
whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.bmp' whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.jpg'
qrInstruct = Image.open(whereQRinstructionsAre) qrInstruct = Image.open(whereQRinstructionsAre)
whereInstructionsPlusQRis = imagesPath + 'instructionsPlusQR.jpg'
get_concat_h_blank(qrInstruct, img, (255, 255, 255)).save(whereInstructionsPlusQRis)
instr = Image.open(whereInstructionsPlusQRis)
# concatenate QR+instructions to full composite for print
#generate unique file_name #generate unique file_name
unique = uuid.uuid4() unique = uuid.uuid4()
unique = str(unique) unique = str(unique)
FULLcomposite = imagesPath + unique + '.jpg' FULLcomposite = imagesPath + unique + '.jpg'
get_concat_v(concaz, (get_concat_h(qrInstruct, img))).save(FULLcomposite) # concatenate existing composite image with the instructions+QR composite for full composite image for print
get_concat_v(concaz, instr).save(FULLcomposite)
# print Fullcomposite # print Fullcomposite
try: try:
result = subprocess.call('lp' + Fullcomposite, shell=True) result = subprocess.call('lp ' + FULLcomposite, shell=True)
except: except:
print('traceback.format_exc():\n%s' % traceback.format_exc()) print('traceback.format_exc():\n%s' % traceback.format_exc())
exit() exit()
#update dbCount #update dbCount
for item in db: for item in db:
dbCount = item.doc_id dbCount = item.doc_id
@ -379,11 +391,11 @@ while True:
#display the image to clear the menu (also display text "posted") #display the image to clear the menu (also display text "posted")
font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24) font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
bmp = Image.open(bmpath) bmp = Image.open(bmpath1)
Limage.paste(bmp) Limage.paste(bmp)
draw = ImageDraw.Draw(Limage) draw = ImageDraw.Draw(Limage)
draw.text((2, 240), 'PHOTO POSTED', font = font18, fill = 255) draw.text((2, 240), 'photostrip posted', font = font18, fill = 255)
draw.text((2, 260), 'online!', font = font18, fill = 255) draw.text((2, 260), 'to SSB', font = font18, fill = 255)
epd.display(epd.getbuffer(Limage)) epd.display(epd.getbuffer(Limage))
@ -416,7 +428,7 @@ while True:
button_flag == "null" button_flag == "null"
#nothin! loop around... exitPhotoMode still false #nothin! loop around... exitPhotoMode still false
#reshoot #reshoot
if (button_flag == "button_4"): if (button_flag == "button_4"):
@ -424,7 +436,7 @@ while True:
exitPhotoMode = True exitPhotoMode = True
os.remove(bmpath) os.remove(bmpath)
os.remove(jpgpath) os.remove(jpgpath)
#exit photo mode #exit photo mode
if (button_flag == "button_5"): if (button_flag == "button_5"):
button_flag == "null" button_flag == "null"

View File

@ -5,7 +5,7 @@
#add blob #add blob
blobID=$(cat $1 | ssb-server blobs.add) blobID=$(cat $1 | ssb-server blobs.add)
echo $blobID #echo $blobID
#publish blob #publish blob
#key=$(ssb-server publish --type post --text "![upload.bmp($blobID)]" #key=$(ssb-server publish --type post --text "![upload.bmp($blobID)]"