Esempio n. 1
0
def multiplexImage_WQR(to, img, qr_data):
    misc.log_t("Multiplex","enter")

    x_offset = 0 # placeholder? not really used
    spaceY = 0 # placeholder? not really used

    (w , h) = paper_size
    (ww , hh) = misc.gSize(img)

    #totalYSpace = h / 10
    #yHl = totalYSpace - 178
    #yH2 = (totalYSpace * 5) + 3

    yH1 = 0
    yH2 = h / 2

    x1Pos = (w / 4) - (ww / 2) # not used yet
    x2Pos = 0

    if(not multiplex_new):
        x2Pos = x_offset + ww # + 1
    else:
        x2Pos = ((w / 4) * 3) - (ww / 2) #x_offset + w - ww

    to.paste(img, (x1Pos , yH1))
    to.paste(img, (x2Pos  , yH1))

    to.paste(img, (x1Pos ,yH2))
    to.paste(img, (x2Pos  ,yH2))

    # paste generated QR
    qr_img = qrcode.make(qr_data).resize( (qr_size, qr_size) , Image.ANTIALIAS)

    qr_x_offset = -20 # -20
    qr_y_offset = -15

    qr_w,qr_h = qr_img.size
    to.paste(qr_img,(x2Pos - qr_w + qr_x_offset ,yH2 - qr_h  + qr_y_offset))
    to.paste(qr_img,(x2Pos - qr_w + qr_x_offset,h - qr_h  + qr_y_offset))

    to.paste(qr_img,(w - qr_w + qr_x_offset,yH2 - qr_h  + qr_y_offset))
    to.paste(qr_img,(w - qr_w + qr_x_offset,h - qr_h  + qr_y_offset))

    misc.log_t("Multiplex","exit")
    return to
Esempio n. 2
0
def draw(img, name, surname, tc, date, ow_name):
    #if(misc.debug):
    misc.log_t("DrawInfo","enter")

    (x,y) = misc.gSize(img)
    x1 = (x / 10) / 4
    y1 = (y / 10) * 4 + 20
    x2 = (x / 15) * 8
    y2 = (y / 10) * 9 + 20

    d = ImageDraw.Draw(img)

    d.text((x1, y1), "ICAO MRTD 9303/3 - ISO/IEC 19794-5", fill='black', font=font_small)
    d.text((x1, y1 + off_name_y), name + " " + surname, fill='black', font=font_normal)
    d.text((x1, y1 + off_id_y), "ID : TR " + tc, fill='black', font=font_normal)
    d.text((x1, y1 + off_date_y), date, fill='black', font=font_msmall)
    d.text((x1 + off_owner_x, y1 + off_owner_y), ow_name, fill='black', font=font_small)

    d.text((x2, y1), "ICAO MRTD 9303/3 - ISO/IEC 19794-5", fill='black', font=font_small)
    d.text((x2, y1 + off_name_y), name + " " + surname, fill='black', font=font_normal)
    d.text((x2, y1 + off_id_y), "ID : TR " + tc, fill='black', font=font_normal)
    d.text((x2, y1 + off_date_y), date, fill='black', font=font_msmall)
    d.text((x2 + off_owner_x, y1 + off_owner_y), ow_name, fill='black', font=font_small)

    d.text((x1, y2), "ICAO MRTD 9303/3 - ISO/IEC 19794-5", fill='black', font=font_small)
    d.text((x1, y2 + off_name_y), name + " " + surname, fill='black', font=font_normal)
    d.text((x1, y2 + off_id_y), "ID : TR " + tc, fill='black', font=font_normal)
    d.text((x1, y2 + off_date_y), date, fill='black', font=font_msmall)
    d.text((x1 + off_owner_x, y2 + off_owner_y), ow_name, fill='black', font=font_small)

    d.text((x2, y2), "ICAO MRTD 9303/3 - ISO/IEC 19794-5", fill='black', font=font_small)
    d.text((x2, y2 + off_name_y), name + " " + surname, fill='black', font=font_normal)
    d.text((x2, y2 + off_id_y), "ID : TR " + tc, fill='black', font=font_normal)
    d.text((x2, y2 + off_date_y), date, fill='black', font=font_msmall)
    d.text((x2 + off_owner_x, y2 + off_owner_y), ow_name, fill='black', font=font_small)

    #val = Image.open("val.png")
    #img.paste(val, (0, 0), val)

    misc.log_t("DrawInfo","exit")
    return img
Esempio n. 3
0
def cropImage(img, box):
    misc.log_t("Crop","FROM " + misc.boxToString(img.getbbox()) + " TO " + misc.boxToString(box))
    return img.crop(box)
Esempio n. 4
0
def run(c_id, name, surname, tc, printnum, x0, y0, z0, r0, brightness, color, archive):
    c_id = c_id.replace('"','')
    misc.log_("Selected Country",c_id)
    misc.log_("Name",name)
    misc.log_("Surname",surname)
    misc.log_("TC",tc)

    photo_id = get_pid(c_id)

    name = name.replace('"','')

    x1 = ast.literal_eval(x0)
    y1 = ast.literal_eval(y0)
    z1 = ast.literal_eval(z0)
    r1 = ast.literal_eval(r0)
    brightness = ast.literal_eval(brightness)
    color = ast.literal_eval(color)

    x1 = -x1
    y1 = -y1

    misc.log_t("Archive - REQUEST",archive);

    if (misc.is_test_mode):
        lImagePath = "cl\\test-stan.jpg"
    else:
        if (archive == "false"):
            lImagePath = lastImage.find()
        else:
            lImagePath = lastImage.g_base() + tc + ".jpg" # needs testing

    misc.log_t("Target File",lImagePath);
    if (os.path.isfile(lImagePath)):
        time = misc.get_time()
        misc.log_("IMG_","Loading : " + lImagePath)

        img_base = Image.open( lImagePath) # Load target image

        # resize image to fit head
        if(photo_id == 1):
            img_base = resizeZScale( img_base, 1 + z_offset_vs) # Resize based on app
            img_base = rotateImage( img_base , 270) # Rotate to fix camera rotation
        else:
            if(photo_id == 5):
                img_base = resizeZScale( img_base, z1 + z_offset_china) # Resize based on app
                img_base = rotateImage( img_base , 270 - int(r1)) # Rotate to fix camera rotation
            else:
                if(photo_id == 4):
                    img_base = resizeZScale( img_base, (z1) + z_offset_USA) # Resize based on app
                    img_base = rotateImage( img_base , 270 - int(r1)) # Rotate to fix camera rotation
                else:
                    img_base = resizeZScale( img_base, z1 + z_offset) # Resize based on app
                    img_base = rotateImage( img_base , 270 - int(r1)) # Rotate to fix camera rotation


        img_base = cropImage( img_base, transform( photo_id ,img_base , imgSize, x1, y1) )
        img_base = cropImage( resizeToSmallSize(img_base) , s_icao) # don't touch breaks the rest
        # apply effects

        if(not brightness == 1):
            misc.log_t("Enhancer","Brightness " + str(brightness))
            enhancer = ImageEnhance.Brightness(img_base)
            img_base = enhancer.enhance(brightness)

        if(not color == 1):
            misc.log_t("Enhancer","Color " + str(color))
            enhancer = ImageEnhance.Color(img_base)
            img_base = enhancer.enhance(color)

        # 4x4 + draw text
        i_out = multiplexImage_WQR( Image.new("RGB", paper_size , "white") , img_base , (qr_base_url + tc + ".jpg"))
        i_out = drawInfo.draw( i_out, name, surname, tc, misc.timeString(time) , owner_name)

        if(photo_id == 3):
            cutlines = cl_schengen
            i_out.paste(cutlines, (0, 0), cutlines)
        else:
            if(photo_id == 4):
                cutlines = cl_usa # cl_usa
                i_out.paste(cutlines, (0, 0), cutlines)
            else:
                if(photo_id == 5):
                    cutlines = cl_china # cl_china.png
                    i_out.paste(cutlines, (0, 0), cutlines)
                else:
                    if(photo_id == 6):
                        cutlines = cl_icao_schengen
                        i_out.paste(cutlines, (0, 0), cutlines)
                    else:
                        cutlines = cl
                        i_out.paste(cutlines, (0, 0), cutlines)

        i_small = cropImage(i_out, small_img_size )
        i_small.save(os.pardir + "\\output\\small\\" + tc + "-sm.jpg")

        file_name = os.pardir + "\\output\\" + tc + ".jpg" #  + misc.timeStringShort(time)

        misc.log_("FILE", "TO '" + file_name + "'")
        i_out.save(file_name)

        print_image_x( i_out, int(printnum))

        return "Print Request Done"
    else:
        return "File find error... Aborted."
Esempio n. 5
0
def rotateImage(img, val):
    misc.log_t("Rotate" ,"%i" % val )
    return img.rotate(val,Image.BICUBIC,True) # BICUBIC