Python QR code Embedded With Images

Python QR code embedded with images:


QR code is basically "quick response" which is also a 2D image and you can easily generate QR code images using Python's QR code.




Installations:

$pip install qrcode


$pip install pillow





1. Translucent QR code embedded with Image

           QR code can be directly pasted on the image and the QR code can be made translucent or the opacity of image can be reduced. Let's see an example  with dog.png image.
Ex:Dog.png
import qrcode
from PIL import Image
from PIL import ImageDraw, ImageFilter
def water_mark(actual_img_path, dest_img_path, fill_color, back_color):
qr_code = qrcode.QRCode(box_size=2)
qr_code.add_data('https://pigirl2020.blogspot.com')
qr_code.make()
qr_code_img = qr_code.make_image(fill_color=fill_color, back_color=back_color)
qr_code_img.putalpha(128)
actual_img = Image.open(actual_img_path)
actual_img_copy = actual_img.copy()
insert_pos = (actual_img_copy.size[0] - qr_code_img.size[0], actual_img_copy.size[1] - qr_code_img.size[1])
actual_img_copy.paste(qr_code_img, insert_pos, qr_code_img)
actual_img_copy.save(dest_img_path)
water_mark('dog.png','result2ß.png','#000000','white')
Result.png             

2. Generating simple python QR code.

          Here with is code you can generate simple QR code you can put any data in the qr.add_data("")
 like link , text data or any other info to generate simple QR code.
 

import qrcode
img = qrcode.make('test text')
print(type(img))
print(img.size)
img.save('test.png')

3. QR code embedded with Image 

  QR code embedded with Image the colour of the QR code can be change by 
qr_code_img = qr_code.make_image(fill_color=fill_color, back_color=back_color)

import qrcode
from PIL import Image
img_actual = Image.open('dog.jpg')
qr = qrcode.QRCode(box_size=2)
qr.add_data('your data')
qr.make()
img_qr = qr.make_image()
pos = (img_actual.size[0] - img_qr.size[0], img_actual.size[1] - img_qr.size[1])
img_actual.paste(img_qr, pos)
img_actual.save('result2.png')


 So, here you can see the image embedded with the QR code




Result2.png

My Instagram

Made with by Pi-girl | Copyright © 2020 Pi-girl