memostack
article thumbnail
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.github.io/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
반응형

1. 모듈 다운로드

  • python 3.4버전 이상
<html />
pip install --upgrade pip pip install qrcode Pillow

 

1.1. 설치 확인

<html />
hong@TaehongcBookPro ~ % python3 Python 3.7.7 (v3.7.7:d7c567b08f, Mar 10 2020, 02:56:16) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import qrcode

 

2. 코딩

<python />
# -*- coding: utf-8 -*- import os import qrcode url = r"https://memostack.tistory.com/" img_format = "png" img_path = r"./grcode.{}".format(img_format) # 만들어진 qrcode 이미지가 있으면 삭제 if os.path.exists(img_path): os.remove(img_path) # qrcode 생성 qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=20, border=10, ) qr.add_data(url) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") # 이미지 저장 img.save(img_path, img_format)
  • 내 블로그 url을 주소를 담은 qrcode를 생성해봤다. 

 

2.1. 결과물 테스트

정상적인 QR Code로 인식

 

2.2. 생성된 QR code 이미지

border, box_size 옵션

  • border: 이미지 테두와 qrcode 사이 간격
  • box_size: 박스(Box) 하나가 이루는 픽셀(pixel) 크기
    • 숫자가 커질수록 박스 1개의 크기가 커진다. (이미지가 커진다)

 

2.3. 색상도 자유롭게 변경 가능

참고로, 색상을 변경할때 qrcode를 인식못하는 색상조합도 있으니 주의하자.

<python />
# ... img = qr.make_image(fill_color="#228be6", back_color="#e7f5ff") # ...

내 블로그 url을 담은 QR code

반응형
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.github.io/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
profile

memostack

@bluemiv_mm

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!