0% found this document useful (0 votes)
16 views9 pages

Python QR Code Generator Guide

The document provides instructions for generating QR codes using the Python library 'qrcode'. It includes examples demonstrating how to create QR codes, customize their properties, and incorporate images into the QR codes. Additionally, it covers the installation process and various methods available in the library.

Uploaded by

hr.rsitek
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

Python QR Code Generator Guide

The document provides instructions for generating QR codes using the Python library 'qrcode'. It includes examples demonstrating how to create QR codes, customize their properties, and incorporate images into the QR codes. Additionally, it covers the installation process and various methods available in the library.

Uploaded by

hr.rsitek
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Python Programming Language

Projects in Python

QR CODE
GENERATOR
Library - qrcode
pip install qrcode
Python has a library “qrcode” for generating QR code
images. It can be installed using pip.
Example -1
# Import library qrcode

import qrcode

data='[Link]

#make function to create qrcode

img=[Link](data)

#save file as image

[Link]('[Link]')
 We can change the properties:
Version: This parameter is an integer from 1 to
40 that controls the size of the QR Code.
box_size: This parameter controls how many
pixels each “box” of the QR code
border: The border parameter define border.
add_data(): This method is used to add data to
the QRCode object.
make(): This method with (fit=True) ensures that
the entire dimension of the QR Code is utilized,
even if our input data could fit into less number
of boxes.
make_image(): This method is used to convert
the QRCode
# Import library qrcode
Example -2
import qrcode
data='[Link]
qr=[Link]( version=1,
box_size=10,
border=5)
# Adding data to the instance 'qr'
qr.add_data(data)
[Link](fit=True)
img = qr.make_image(fill_color = 'red',
back_color = 'white')
#save file as image
[Link]('[Link]')
pip install Image Example -3
imort qrcode
from PIL import Image
img_bg = [Link]('[Link]')
qr = [Link](box_size=2)
qr.add_data('[Link]
[Link]()
img_qr = qr.make_image()
pos = (img_bg.size[0] - img_qr.size[0],
img_bg.size[1] - img_qr.size[1])
img_bg.paste(img_qr, pos)
img_bg.save('qr_lena.png')
# import modules
import qrcode
from PIL import Image
Example -4
# image in QR code center
Logo = '[Link]'

logo = [Link](Logo)

[Link]((120,120))
QRcode = [Link]()

# taking url or text


url = '[Link]

# adding URL or text to QRcode


QRcode.add_data(url)

# generating QR code
[Link]()

# adding color to QR code


QRimg = QRcode.make_image(
fill_color='Black', back_color="white").convert('RGB')

[Link](logo, (100,100))

# save the QR code generated


[Link]('gfg_QR.png')

print('QR code generated!')


# import modules
import qrcode
from PIL import Image Example -4
# image in QR code center
Logo = '[Link]'

logo = [Link](Logo)

# taking base width


#basewidth = 20

# adjust image size


#wpercent = (basewidth/float([Link][0]))
[Link]((120,120))
QRcode = [Link]()
# set size of QR code
# taking url or text #pos = (([Link][0] - [Link][0]) //2,
url = '[Link] # ([Link][1] - [Link][1]) // 2)
[Link](logo, (100,100))
# adding URL or text to QRcode
QRcode.add_data(url) # save the QR code generated
[Link]('gfg_QR.png')
# generating QR code
[Link]() print('QR code generated!')
# adding color to QR code
QRimg = QRcode.make_image(
fill_color='Black',
back_color="white").convert('RGB')
Thanks

You might also like