コード例 #1
0
def do_variety_demo():
	"""Creates a variety of QR Codes that exercise different features of the library, and prints each one to the console."""
	
	# Numeric mode encoding (3.33 bits per digit)
	qr = QrCode.encode_text("314159265358979323846264338327950288419716939937510", QrCode.Ecc.MEDIUM)
	print_qr(qr)
	
	# Alphanumeric mode encoding (5.5 bits per character)
	qr = QrCode.encode_text("DOLLAR-AMOUNT:$39.87 PERCENTAGE:100.00% OPERATIONS:+-*/", QrCode.Ecc.HIGH)
	print_qr(qr)
	
	# Unicode text as UTF-8
	qr = QrCode.encode_text(u"\u3053\u3093\u306B\u3061\u0077\u0061\u3001\u4E16\u754C\uFF01\u0020\u03B1\u03B2\u03B3\u03B4", QrCode.Ecc.QUARTILE)
	print_qr(qr)
	
	# Moderately large QR Code using longer text (from Lewis Carroll's Alice in Wonderland)
	qr = QrCode.encode_text(
		"Alice was beginning to get very tired of sitting by her sister on the bank, "
		"and of having nothing to do: once or twice she had peeped into the book her sister was reading, "
		"but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice "
		"'without pictures or conversations?' So she was considering in her own mind (as well as she could, "
		"for the hot day made her feel very sleepy and stupid), whether the pleasure of making a "
		"daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly "
		"a White Rabbit with pink eyes ran close by her.", QrCode.Ecc.HIGH)
	print_qr(qr)
コード例 #2
0
def create_svg():
    #errcorlvl = QrCode.Ecc.QUARTILE # Error correction level. Need to determine best setting!
    errcorlvl = QrCode.Ecc.LOW
    svg_list = []

    with open(temp_file, newline='') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',', quotechar='|')
        try:
            for row in csv_reader:
                qr_pub = QrCode.encode_text(row[1], errcorlvl)
                qr_svg_pub = qr_pub.to_svg_str(4)
                #logger.debug('PUBLIC')
                #logger.debug(qr_svg_pub)
                file_name_pub = output_path + row[0] + '_pub.svg'
                logger.debug(file_name_pub)
                with open(file_name_pub, 'w') as svg_file:
                    svg_file.write(qr_svg_pub)
                
                qr_priv = QrCode.encode_text(row[2], errcorlvl)
                qr_svg_priv = qr_priv.to_svg_str(4)
                #logger.debug('PRIVATE')
                #logger.debug(qr_svg_priv)
                file_name_priv = output_path + row[0] + '_priv.svg'
                logger.debug(file_name_priv)
                with open(file_name_priv, 'w') as svg_file:
                    svg_file.write(qr_svg_priv)

        except Exception as e:
            logger.exception('Exception while creating svg files.')
            logger.exception(e)
            raise
コード例 #3
0
def do_variety_demo():
    """Creates a variety of QR Codes that exercise different features of the library, and prints each one to the console."""

    # Numeric mode encoding (3.33 bits per digit)
    qr = QrCode.encode_text(
        "314159265358979323846264338327950288419716939937510",
        QrCode.Ecc.MEDIUM)
    print_qr(qr)

    # Alphanumeric mode encoding (5.5 bits per character)
    qr = QrCode.encode_text(
        "DOLLAR-AMOUNT:$39.87 PERCENTAGE:100.00% OPERATIONS:+-*/",
        QrCode.Ecc.HIGH)
    print_qr(qr)

    # Unicode text as UTF-8
    qr = QrCode.encode_text(
        u"\u3053\u3093\u306B\u3061\u0077\u0061\u3001\u4E16\u754C\uFF01\u0020\u03B1\u03B2\u03B3\u03B4",
        QrCode.Ecc.QUARTILE)
    print_qr(qr)

    # Moderately large QR Code using longer text (from Lewis Carroll's Alice in Wonderland)
    qr = QrCode.encode_text(
        "Alice was beginning to get very tired of sitting by her sister on the bank, "
        "and of having nothing to do: once or twice she had peeped into the book her sister was reading, "
        "but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice "
        "'without pictures or conversations?' So she was considering in her own mind (as well as she could, "
        "for the hot day made her feel very sleepy and stupid), whether the pleasure of making a "
        "daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly "
        "a White Rabbit with pink eyes ran close by her.", QrCode.Ecc.HIGH)
    print_qr(qr)
コード例 #4
0
def create_svg(addr, name):
    os.chdir('../../..')

    # Error Correction Levels #
    # LOW / MEDIUM / QUARTILE / HIGH
    errcorlvl = QrCode.Ecc.QUARTILE  # Error correction level. Need to determine best setting!

    try:
        qr_data = 'bitcoin:' + addr
        qr_pub = QrCode.encode_text(qr_data, errcorlvl)
        qr_svg_pub = qr_pub.to_svg_str(4)

        file_name_pub = wallet_dir + name + '_pub.svg'
        logger.debug(file_name_pub)

        with open(file_name_pub, 'w') as svg_file:
            svg_file.write(qr_svg_pub)

        if convert_svg == True:
            png_file = wallet_dir + name + '_pub.png'
            svg2png(bytestring=qr_svg_pub, write_to=png_file)

    except Exception as e:
        logger.exception('Exception while creating svg files.')
        logger.exception(e)
        raise
コード例 #5
0
def create_qr(addr, name):
    global qr_png_path

    qr_svg_path = name + '_qr.svg'
    logger.debug('QR svg path: ' + qr_svg_path)

    qr_png_path = qr_svg_path.strip('.svg') + '.png'
    logger.debug('QR png path: ' + qr_png_path)

    try:
        # Error Correction Levels #
        # LOW / MEDIUM / QUARTILE / HIGH
        errcorlvl = QrCode.Ecc.QUARTILE

        qr_data = 'bitcoin:' + addr
        qr_pub = QrCode.encode_text(qr_data, errcorlvl)
        qr_svg_pub = qr_pub.to_svg_str(4)

        with open(qr_svg_path, 'w') as svg_file:
            svg_file.write(qr_svg_pub)

        with open(qr_svg_path, 'rb') as svg_file:
            svg2png(file_obj=svg_file,
                    write_to=qr_png_path,
                    parent_width=512,
                    parent_height=512)

    except Exception as e:
        logger.exception('Exception while creating QR file.')
        logger.exception(e)
        raise
コード例 #6
0
def generate_qr_code(curriculum):
    text = 'pajk://consult_fitnessmainpage_jump?content={"curriculumId":"%s","index":"1"}' % (curriculum.id,)
    qr0 = QrCode.encode_text(text, QrCode.Ecc.MEDIUM)
    svg = '%s.svg' % (curriculum.ref_no,)
    with open(svg, 'w') as f:
        f.write(qr0.to_svg_str(4))
    return svg
コード例 #7
0
def do_basic_demo():
    """Creates a single QR Code, then prints it to the console."""
    text = u"Hello, world!"  # User-supplied Unicode text
    errcorlvl = QrCode.Ecc.LOW  # Error correction level

    # Make and print the QR Code symbol
    qr = QrCode.encode_text(text, errcorlvl)
    print_qr(qr)
    print(qr.to_svg_str(4))
コード例 #8
0
def do_basic_demo():
	"""Creates a single QR Code, then prints it to the console."""
	text = u"Hello, world!"     # User-supplied Unicode text
	errcorlvl = QrCode.Ecc.LOW  # Error correction level
	
	# Make and print the QR Code symbol
	qr = QrCode.encode_text(text, errcorlvl)
	print_qr(qr)
	print(qr.to_svg_str(4))
コード例 #9
0
def test(text="QR Code Test", ecc_quality=QrCode.Ecc.LOW):
    gc.collect()
    print(micropython.mem_info())
    t = utime.ticks_ms()
    dt1 = utime.ticks_diff(utime.ticks_ms(), t)
    t = utime.ticks_ms()
    qr0 = QrCode.encode_text(text, ecc_quality)
    dt2 = utime.ticks_diff(utime.ticks_ms(), t)
    t = utime.ticks_ms()
    modules = qr0._modules
    dt3 = utime.ticks_diff(utime.ticks_ms(), t)
    print(dt1, dt2, dt3)
    gc.collect()
    print(micropython.mem_info())
コード例 #10
0
def make_one_qr_svg(color,
                    design,
                    eyes,
                    eye_color,
                    type,
                    value,
                    logo,
                    grid,
                    errcorlvl,
                    width_cm='3cm',
                    height_cm='3cm'):
    qr = QrCode.encode_text(value, errcorlvl)
    if design == 'special':
        body = get_special(qr=qr, color=color)
    if design == 'round':
        body = get_cirles(qr=qr, color=color)
    if design == 'square':
        body = get_squares(qr=qr, color=color)
    eyes = get_squared_eyes(qr=qr, color=eye_color)
    qr_code = "\n".join([body, eyes])
    scale_factor = 80 / qr._size

    svg_wrapper_template = """
	<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100" stroke="none" width="{width_cm}" height="{height_cm}">
		{content}
	</svg>"""

    svg_qr_content_template = """
		<rect width="100" height="100" fill="#FFFFFF"/>
		<g transform="translate(10 10)" id="QR_BODY">
			<g transform="scale({scale_factor})">
				{qr_code}
				{mingl_logo}
			</g>
		</g>
		{mingl_text}
	"""

    mingl_text = svg_mingl_text_template
    svg_qr_code_without_logo = svg_qr_content_template.format(
        qr_code=qr_code,
        scale_factor=scale_factor,
        mingl_text=mingl_text,
        mingl_logo='{mingl_logo}')
    svg_qr_code = addLogo(svg_qr_code_without_logo, logo, qr._size)
    if not grid:
        svg_qr_code = svg_wrapper_template.format(content=svg_qr_code,
                                                  width_cm=width_cm,
                                                  height_cm=height_cm)
    return svg_qr_code
コード例 #11
0
def create_svg(input_file):
    global output_dir

    errcorlvl = QrCode.Ecc.QUARTILE  # Error correction level. Need to determine best setting!
    svg_list = []

    with open(input_file, newline='') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',', quotechar='|')
        try:
            count = 0
            output_dir_initial = output_dir
            for row in csv_reader:
                count += 1
                output_dir = output_dir_initial + str(count) + '/'
                os.makedirs(output_dir)

                qr_pub = QrCode.encode_text(row[1], errcorlvl)
                qr_svg_pub = qr_pub.to_svg_str(4)
                #logger.debug('PUBLIC')
                #logger.debug(qr_svg_pub)
                file_name_pub = output_dir + str(count) + '_pub.svg'
                logger.debug(file_name_pub)

                with open(file_name_pub, 'w') as svg_file:
                    svg_file.write(qr_svg_pub)

                #qr_priv = QrCode.encode_text(row[4], errcorlvl)
                #qr_svg_priv = qr_priv.to_svg_str(4)
                #logger.debug('PRIVATE')
                #logger.debug(qr_svg_priv)
                #file_name_priv = output_dir + str(count) + '_priv.svg'
                #logger.debug(file_name_priv)

                #with open(file_name_priv, 'w') as svg_file:
                #svg_file.write(qr_svg_priv)

                file_name_info = output_dir + str(count) + '_info.txt'
                with open(file_name_info, 'w') as info_file:
                    info_file.write(row[0])
                    info_file.write('\n\n')
                    info_file.write(row[1])
                    #info_file.write('\n\n')
                    #info_file.write(row[4])

        except Exception as e:
            logger.exception('Exception while creating svg files.')
            logger.exception(e)
            raise
コード例 #12
0
ファイル: test_two_factor_auth.py プロジェクト: Syfaro/weasyl
def test_init():
    """
    Verify we get a usable 2FA Secret and QRCode from init()
    """
    user_id = db_utils.create_user()
    tfa_secret, tfa_qrcode = tfa.init(user_id)

    computed_uri = pyotp.TOTP(tfa_secret).provisioning_uri(d.get_display_name(user_id), issuer_name="Weasyl")
    qr = QrCode.encode_text(computed_uri, QrCode.Ecc.MEDIUM)
    qr_xml = qr.to_svg_str(4)
    # We only care about the content in the <svg> tags; strip '\n' to permit re.search to work
    qr_svg_only = re.search(r"<svg.*<\/svg>", qr_xml.replace('\n', '')).group(0)
    computed_qrcode = urllib.quote(qr_svg_only)
    # The QRcode we make locally should match that from init()
    assert tfa_qrcode == computed_qrcode
    # The tfa_secret from init() should be 16 characters, and work if passed in to pyotp.TOTP.now()
    assert len(tfa_secret) == 16
    assert len(pyotp.TOTP(tfa_secret).now()) == tfa.LENGTH_TOTP_CODE
コード例 #13
0
def test_init():
    """
    Verify we get a usable 2FA Secret and QRCode from init()
    """
    user_id = db_utils.create_user()
    tfa_secret, tfa_qrcode = tfa.init(user_id)

    computed_uri = pyotp.TOTP(tfa_secret).provisioning_uri(
        d.get_display_name(user_id), issuer_name="Weasyl")
    qr = QrCode.encode_text(computed_uri, QrCode.Ecc.MEDIUM)
    qr_xml = qr.to_svg_str(4)
    # We only care about the content in the <svg> tags; strip '\n' to permit re.search to work
    qr_svg_only = re.search(r"<svg.*<\/svg>", qr_xml.replace('\n',
                                                             '')).group(0)
    computed_qrcode = urlquote(qr_svg_only)
    # The QRcode we make locally should match that from init()
    assert tfa_qrcode == computed_qrcode
    # The tfa_secret from init() should be 16 characters, and work if passed in to pyotp.TOTP.now()
    assert len(tfa_secret) == 16
    assert len(pyotp.TOTP(tfa_secret).now()) == tfa.LENGTH_TOTP_CODE
コード例 #14
0
def create_qr(addr, name):
    qr_file_path = name + '_qr.svg'
    logger.debug('QR file path: ' + qr_file_path)

    try:
        # Error Correction Levels #
        # LOW / MEDIUM / QUARTILE / HIGH
        errcorlvl = QrCode.Ecc.QUARTILE  # Error correction level. Need to determine best setting!

        qr_data = 'bitcoin:' + addr
        qr_pub = QrCode.encode_text(qr_data, errcorlvl)
        qr_svg_pub = qr_pub.to_svg_str(4)

        with open(qr_file_path, 'w') as svg_file:
            svg_file.write(qr_svg_pub)

    except Exception as e:
        logger.exception('Exception while creating QR file.')
        logger.exception(e)
        raise
コード例 #15
0
def create_svg(addr, name):
    os.chdir('../../..')

    errcorlvl = QrCode.Ecc.HIGH  # Error correction level. Need to determine best setting!

    try:
        qr_data = 'bitcoin:' + addr
        qr_pub = QrCode.encode_text(qr_data, errcorlvl)
        qr_svg_pub = qr_pub.to_svg_str(4)

        file_name_pub = wallet_dir + name + '_pub.svg'
        logger.debug(file_name_pub)

        with open(file_name_pub, 'w') as svg_file:
            svg_file.write(qr_svg_pub)

    except Exception as e:
        logger.exception('Exception while creating svg files.')
        logger.exception(e)
        raise
コード例 #16
0
ファイル: two_factor_auth.py プロジェクト: Syfaro/weasyl
def generate_tfa_qrcode(userid, tfa_secret):
    """
    Generate a 2FA QRCode on-demand, with the provisioning URI based on the supplied 2FA-secret.

    Used as a helper function for init(), or to regenerate the QRCode from a failed attempt
    at verifying the init()/init_verify_tfa() phases.

    Parameters:
        userid: The userid for the calling user; used to retrieve the username for the provisioning URI.
        tfa_secret: The tfa_secret as generated from init(), initially.

    Returns: A URL-quoted SVG--containing the TOTP provisioning URI--capable of being inserted into
             a data-uri for display to the user.
    """
    totp_uri = pyotp.TOTP(tfa_secret).provisioning_uri(d.get_display_name(userid), issuer_name="Weasyl")
    # Generate the QRcode
    qr = QrCode.encode_text(totp_uri, QrCode.Ecc.MEDIUM)
    qr_xml = qr.to_svg_str(4)
    # We only care about the content in the <svg> tags; strip '\n' to permit re.search to work
    qr_svg_only = re.search(r"<svg.*<\/svg>", qr_xml.replace('\n', '')).group(0)
    return urllib.quote(qr_svg_only)
コード例 #17
0
ファイル: two_factor_auth.py プロジェクト: bubbt/weasyl
def generate_tfa_qrcode(userid, tfa_secret):
    """
    Generate a 2FA QRCode on-demand, with the provisioning URI based on the supplied 2FA-secret.

    Used as a helper function for init(), or to regenerate the QRCode from a failed attempt
    at verifying the init()/init_verify_tfa() phases.

    Parameters:
        userid: The userid for the calling user; used to retrieve the username for the provisioning URI.
        tfa_secret: The tfa_secret as generated from init(), initially.

    Returns: A URL-quoted SVG--containing the TOTP provisioning URI--capable of being inserted into
             a data-uri for display to the user.
    """
    totp_uri = pyotp.TOTP(tfa_secret).provisioning_uri(
        d.get_display_name(userid), issuer_name="Weasyl")
    # Generate the QRcode
    qr = QrCode.encode_text(totp_uri, QrCode.Ecc.MEDIUM)
    qr_xml = qr.to_svg_str(4)
    # We only care about the content in the <svg> tags; strip '\n' to permit re.search to work
    qr_svg_only = re.search(r"<svg.*<\/svg>", qr_xml.replace('\n',
                                                             '')).group(0)
    return urllib.quote(qr_svg_only)
コード例 #18
0
ファイル: qr-gen.py プロジェクト: smolsbs/random
    def makeQrImage(self, data=None):
        """Creates the QR code.
        Data is provided either by an argument, or already in self.data 

        Args:
            data (str, optional): data to generate the qr code. Defaults to None.

        Raises:
            Exception: If no data is passed and there is None in self.data
        """
        if data is None and self.data is None:
            raise Exception('No data found.')
        if data is not None:
            self.data = data

        try:
            svg = QrCode.encode_text(self.data, QrCode.Ecc.LOW).to_svg_str(2)
        except DataTooLongError:
            print('Size of the data is too big. Please lower it')
            sys.exit(1)

        self.fn = self.findTmp() + self.createRandomName()
        svg2png(svg, scale=10, write_to=self.fn)
コード例 #19
0
def do_segment_demo():
    """Creates QR Codes with manually specified segments for better compactness."""

    # Illustration "silver"
    silver0 = "THE SQUARE ROOT OF 2 IS 1."
    silver1 = "41421356237309504880168872420969807856967187537694807317667973799"
    qr = QrCode.encode_text(silver0 + silver1, QrCode.Ecc.LOW)
    print_qr(qr)

    segs = [
        QrSegment.make_alphanumeric(silver0),
        QrSegment.make_numeric(silver1)
    ]
    qr = QrCode.encode_segments(segs, QrCode.Ecc.LOW)
    print_qr(qr)

    # Illustration "golden"
    golden0 = u"Golden ratio \u03C6 = 1."
    golden1 = u"6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374"
    golden2 = u"......"
    qr = QrCode.encode_text(golden0 + golden1 + golden2, QrCode.Ecc.LOW)
    print_qr(qr)

    segs = [
        QrSegment.make_bytes(golden0.encode("UTF-8")),
        QrSegment.make_numeric(golden1),
        QrSegment.make_alphanumeric(golden2)
    ]
    qr = QrCode.encode_segments(segs, QrCode.Ecc.LOW)
    print_qr(qr)

    # Illustration "Madoka": kanji, kana, Cyrillic, full-width Latin, Greek characters
    madoka = u"\u300C\u9B54\u6CD5\u5C11\u5973\u307E\u3069\u304B\u2606\u30DE\u30AE\u30AB\u300D\u3063\u3066\u3001\u3000\u0418\u0410\u0418\u3000\uFF44\uFF45\uFF53\uFF55\u3000\u03BA\u03B1\uFF1F"
    qr = QrCode.encode_text(madoka, QrCode.Ecc.LOW)
    print_qr(qr)

    kanjiCharBits = [  # Kanji mode encoding (13 bits per character)
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        0,
        1,
        0,
        1,
        1,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        1,
        1,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        1,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        1,
        1,
        1,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        1,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        0,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
    ]
    segs = [
        QrSegment(QrSegment.Mode.KANJI,
                  len(kanjiCharBits) // 13, kanjiCharBits)
    ]
    qr = QrCode.encode_segments(segs, QrCode.Ecc.LOW)
    print_qr(qr)
コード例 #20
0
def print_qrcode(text, ecc):
    # Make public QR Code symbol
    qr = QrCode.encode_text(text, ecc)
    print_qr(qr)
コード例 #21
0
def do_segment_demo():
	"""Creates QR Codes with manually specified segments for better compactness."""
	
	# Illustration "silver"
	silver0 = "THE SQUARE ROOT OF 2 IS 1."
	silver1 = "41421356237309504880168872420969807856967187537694807317667973799"
	qr = QrCode.encode_text(silver0 + silver1, QrCode.Ecc.LOW)
	print_qr(qr)
	
	segs = [
		QrSegment.make_alphanumeric(silver0),
		QrSegment.make_numeric(silver1)]
	qr = QrCode.encode_segments(segs, QrCode.Ecc.LOW)
	print_qr(qr)
	
	# Illustration "golden"
	golden0 = u"Golden ratio \u03C6 = 1."
	golden1 = u"6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374"
	golden2 = u"......"
	qr = QrCode.encode_text(golden0 + golden1 + golden2, QrCode.Ecc.LOW)
	print_qr(qr)
	
	segs = [
		QrSegment.make_bytes(golden0.encode("UTF-8")),
		QrSegment.make_numeric(golden1),
		QrSegment.make_alphanumeric(golden2)]
	qr = QrCode.encode_segments(segs, QrCode.Ecc.LOW)
	print_qr(qr)
	
	# Illustration "Madoka": kanji, kana, Cyrillic, full-width Latin, Greek characters
	madoka = u"\u300C\u9B54\u6CD5\u5C11\u5973\u307E\u3069\u304B\u2606\u30DE\u30AE\u30AB\u300D\u3063\u3066\u3001\u3000\u0418\u0410\u0418\u3000\uFF44\uFF45\uFF53\uFF55\u3000\u03BA\u03B1\uFF1F"
	qr = QrCode.encode_text(madoka, QrCode.Ecc.LOW)
	print_qr(qr)
	
	kanjiCharBits = [  # Kanji mode encoding (13 bits per character)
		0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1,
		1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
		0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
		0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1,
		0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
		0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0,
		0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1,
		0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1,
		0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1,
		0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1,
		0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1,
		0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0,
		0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0,
		0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1,
		0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
		0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
		0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,
		0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1,
		0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
		0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
	]
	segs = [QrSegment(QrSegment.Mode.KANJI, len(kanjiCharBits) // 13, kanjiCharBits)]
	qr = QrCode.encode_segments(segs, QrCode.Ecc.LOW)
	print_qr(qr)
コード例 #22
0
def svg_qrcode(text, ecc):
    qr = QrCode.encode_text(text, ecc)
    print(qr.to_svg_str(4))
コード例 #23
0
    print("Resized Resolution:{0}".format((embed.width, embed.height)))

    imgData = image.load()
    for y in range(image.height):
        for x in range(image.width):
            imgData[x, y] = (255, 255, 255)

    for y in range(qrcode.get_size()):
        for x in range(qrcode.get_size()):
            if qrcode.get_module(x, y) == True:
                for zy in range(magnify):
                    for zx in range(magnify):
                        imgData[x * magnify + zx + border,
                                y * magnify + zy + border] = (0, 0, 0)

    for y in range(embed.height):
        for x in range(embed.width):
            imgData[border + (qrcode.get_size() / 2) * magnify -
                    int(embed.width * 0.5) + x,
                    border + (int(qrcode.get_size() * 0.5)) * magnify -
                    int(embed.height / 2) + y] = embed.getpixel((x, y))

    image.resize((image_size, image_size))
    image.save(output, "PNG")


qr = QrCode.encode_text(sys.argv[1], QrCode.Ecc.HIGH)

embed_image = Image.open(sys.argv[2])
qr_embed_image(qr, embed_image, sys.argv[3], int(sys.argv[4]))
コード例 #24
0
ファイル: qrgen-demo.py プロジェクト: sion831/Wantok
        embed = embed.resize((int(image.width * 0.4), int(image.height * 0.4)))
                     
        print("Image Resolution:{0}".format((image.width, image.height)))
        print("Resized Resolution:{0}".format((embed.width, embed.height)))

        imgData = image.load()
        for y in range(image.height):
                for x in range(image.width):
                        imgData[x, y] = (255, 255, 255)
        
        for y in range(qrcode.get_size()):
                for x in range(qrcode.get_size()):
                        if qrcode.get_module(x, y) == True:
                                for zy in range(magnify):
                                        for zx in range(magnify):
                                                imgData[x*magnify+zx+border, y*magnify+zy+border] = (0, 0, 0)

        for y in range(embed.height):
                for x in range(embed.width):
                        imgData[border + (qrcode.get_size()/2)*magnify- int(embed.width*0.5)+ x, border + (int(qrcode.get_size()*0.5))*magnify-int(embed.height/2)+y] = embed.getpixel((x, y))

        image.resize((image_size, image_size))                              
        image.save(output, "PNG")


qr = QrCode.encode_text('https://192.168.0.2:3000/trackers/2018052200001', QrCode.Ecc.HIGH)

embed_image = Image.open('../public/images/filename.jpg')
qr_embed_image(qr, embed_image, '../public/images/brands/qr_vil_01.png', 250)

コード例 #25
0
ファイル: benchmarks.py プロジェクト: stefanoborini/segno
 def create_qrcodegen(data='QR Code Symbol'):
     """qrcodegen create"""
     QrCode.encode_text(data, QrCode.Ecc.MEDIUM)
コード例 #26
0
ファイル: benchmarks.py プロジェクト: stefanoborini/segno
 def svg_qrcodegen(data='QR Code Symbol'):
     """qrcodegen SVG"""
     with open('out/qrcodegen_%s.svg' % data, 'wt') as f:
         f.write(
             QrCode.encode_text(data,
                                QrCode.Ecc.MEDIUM).to_svg_str(border=4))