예제 #1
0
def placeNames():
    try:
        center = Image.open(centerFile)
    except:
        print("placer: couldn't open center PNG")
        #sys exit, shut down threads?
    
    backing = Image.new('RGBA', (board_l,board_h), color=(255,255,255,255))
    draw = ImageDraw.Draw(backing)
    
    #overlay center keepout
    print("placer: making virtual backing, secretly")
    center_l, center_h = center.size
    
    centerPos_l = int((board_l / 2) - (center_l / 2))
    centerPos_h = int((board_h / 2) - (center_h / 2))
    
    backing.alpha_composite(center, (centerPos_l, centerPos_h))
    
    #create backing image based on db
    nameWasPlaced = (Sub
                     .select()
                     .where(Sub.status >= placed)
                    )
    
    for place in nameWasPlaced:
        font = ImageFont.truetype(ttfFont, place.fontSize)
        draw.text((place.positionX,place.positionY), place.userName, (0,0,0), font = font)
    
    #check database for names to place
    nameToPlace = (Sub
             .select()
             .where(Sub.status == entered)
             .order_by(Sub.entryTime)
            )
    
    for sub in nameToPlace:
        LED_TYel.on()
        
        totalEntries = Sub.select().where(Sub.status >= placed).count()
        
        fontSize = fscale(fontMin, fontMax, totalEntries, curve)
        
        blurRad = int(fontSize/bScale) #pixel radius of blur
        
        fail = True
        print("placer: " + sub.userName)
        
        #this should be a function for font choice based on number of existing names
        #the database population function/module/program should do this
        font = ImageFont.truetype(ttfFont, fontSize)
        l,h = font.getsize(sub.userName)
        l += (blurRad * 2)
        h += (blurRad * 2)
        
        textBox = Image.new('RGBA', (l,h), color=(255,255,255,255))
        draw1 = ImageDraw.Draw(textBox)
        
        draw1.text((blurRad,blurRad), sub.userName, (0,0,0), font = font)
        
        textBox = textBox.filter(ImageFilter.GaussianBlur(radius=blurRad))
        
        while fail == True:
            #instead just do a random location for test
            board_l2 = board_l - l
            board_h2 = board_h - h
            pixOffset = border * pixMM
            Rboard_l = random.randint((0 + pixOffset),(board_l2 - pixOffset))
            Rboard_h = random.randint((0 + pixOffset),(board_h2 - pixOffset))
            fail = False
            
            #look for collision
            for i in range(0, l, 1):
                for j in range(0, h, 1):
                    shift_l = i + Rboard_l
                    shift_h = j + Rboard_h

                    r, g, b, a = backing.getpixel((shift_l, shift_h))
                    r1, g1, b1, a1 = textBox.getpixel((i, j))

                    #compare backing to text for overlap
                    if (r,g,b,a) != (255,255,255,255) and (r1,g1,b1,a1) != (255,255,255,255):
                        print("placer: :failfish:")
                        LED_TYel.blink()
                        fail = True
                        break
                if fail == True:
                    break
                 
        #now overlay that onto the board
        draw.text((Rboard_l+blurRad,Rboard_h+blurRad), sub.userName, (0,0,0), font = font)
        
        #update db with good location
        #sub.transaction(lock_type=None)
        sub.positionX = Rboard_l + blurRad
        sub.positionY = Rboard_h + blurRad
        sub.fontSize = fontSize
        sub.status = placed
        sub.save()
        LED_TYel.off()
        makeGcode(sub)
예제 #2
0
def main():
    try:
        center = Image.open(centerFile)
    except:
        print("placer: couldn't open center PNG")
        #sys exit, shut down threads?

    backing = Image.new('RGBA', (board_l, board_h), color=(255, 255, 255, 255))
    draw = ImageDraw.Draw(backing)

    #overlay center keepout
    print("placer: making virtual backing, secretly")
    center_l, center_h = center.size

    centerPos_l = int((board_l / 2) - (center_l / 2))
    centerPos_h = int((board_h / 2) - (center_h / 2))

    backing.alpha_composite(center, (centerPos_l, centerPos_h))

    #create backing image based on db
    nameWasPlaced = (Sub.select().where(Sub.status >= gcode).order_by(
        Sub.entryTime))
    i = 0
    filename = "sequence png/sequence%03d.png" % (i, )
    reBacking = backing.resize(size, Image.LANCZOS)
    nuBacking = Image.new('RGBA', (1920, 1080), color=(0, 0, 0, 0))
    nuBacking.alpha_composite(reBacking, (0, 305))
    nuDraw = ImageDraw.Draw(nuBacking)
    userNumText = "Entries: 000"
    nuFont = ImageFont.truetype(ttfFont, 72)
    nuDraw.text((5, 800), userNumText, (255, 255, 255), font=nuFont)
    nuBacking.save(filename)
    #reBacking.save(filename)
    #backing.save("sequence png/sequence_unscale.png")
    i = 1

    for place in nameWasPlaced:
        font = ImageFont.truetype(ttfFont, place.fontSize)
        draw.text((place.positionX, place.positionY),
                  place.userName, (0, 0, 0),
                  font=font)

        #write the test image of the board
        print("printing output")
        filename = "sequence png/sequence%03d.png" % (i, )
        reBacking = backing.resize(size, Image.LANCZOS)

        nuBacking = Image.new('RGBA', (1920, 1080), color=(48, 48, 48, 255))
        nuBacking.alpha_composite(reBacking, (0, 305))
        nuDraw = ImageDraw.Draw(nuBacking)
        userNumText = "Entries: %03d" % (i, )
        nuFont = ImageFont.truetype(ttfFont, 72)
        nuDraw.text((5, 800), userNumText, (255, 255, 255), font=nuFont)
        l, h = nuFont.getsize(place.userName)
        position = (1920 - 5) - l
        nuDraw.text((position, 800),
                    place.userName, (255, 255, 255),
                    font=nuFont,
                    anchor='Right')
        nuBacking.save(filename)
        i += 1