Last active
November 15, 2024 11:14
-
-
Save Mehran1022mm/3ce5962b6769580719128a06473d8e42 to your computer and use it in GitHub Desktop.
customizable QR code for a specified URL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qrcode | |
from PIL import Image, ImageDraw | |
def create_qr_code(data, foreground_color, background_color): | |
qr_code = qrcode.QRCode( | |
version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_H, | |
box_size=10, | |
border=4, | |
) | |
qr_code.add_data(data) | |
qr_code.make(fit=True) | |
qr_image = qr_code.make_image(fill=foreground_color, back_color=background_color).convert('RGB') | |
background_image = Image.new('RGB', qr_image.size, background_color) | |
draw = ImageDraw.Draw(background_image) | |
qr_width, qr_height = qr_image.size | |
for y in range(qr_height): | |
for x in range(qr_width): | |
if qr_image.getpixel((x, y)) == (0, 0, 0): | |
draw.point((x, y), fill=foreground_color) | |
return background_image | |
if __name__ == "__main__": | |
qr_data = "https://github.com/Mehran1022mm" | |
qr_foreground_color = '#a71616' | |
qr_background_color = '#050404' | |
generated_qr_code_image = create_qr_code(qr_data, qr_foreground_color, qr_background_color) | |
generated_qr_code_image.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment