Skip to content

Instantly share code, notes, and snippets.

@hujuu
Created July 12, 2022 23:00
Show Gist options
  • Save hujuu/3315ce900f0e27230c837391b5aaeee8 to your computer and use it in GitHub Desktop.
Save hujuu/3315ce900f0e27230c837391b5aaeee8 to your computer and use it in GitHub Desktop.
CSV形式の改行文字列からQRコードを生成してPNG形式で保存します
import qrcode
from csv import reader
with open('***.csv', 'r') as csv_file:
csv_reader = reader(csv_file)
list_of_rows = list(csv_reader)
for row in list_of_rows:
# QRコード化したい文字列
QR_STR = row[0]
# QRコード画像ファイル名
QR_FILE_NAME = f'qr_code/result_{row[0][-24:]}.png'
# QRコードの設定
qr = qrcode.QRCode(
version=2, # QRコードのバージョン(1~40)
error_correction=qrcode.constants.ERROR_CORRECT_H # 誤り訂正レベル(L:約7%,M:約15%,Q:約25%,H:約30%)
)
# QRコード化したい文字列を追加
qr.add_data(QR_STR)
# QRコード作成
qr.make()
# QRコードの画像化
img = qr.make_image()
# 画像ファイルを保存
img.save(QR_FILE_NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment