eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

Python

QRコードと画像を組み合わせてQRコード風の芸術的な二次元バーコード画像を作成する CuteR / ArtCoder / MyQR / Amazing-QR / Quick QR Art

更新日:

CuteR

https://github.com/chinuno-usami/CuteR

pip install CuteR

CuteR -c 10 -e H -o sample_output.png -v 10 sample_input.png http://www.chinuno.com
CuteR -C -r 100 50 100 188 sample_input.png http://www.chinuno.com #colourful mode

# -*- coding: utf-8 -*-

from PIL import Image
from PIL import ImageEnhance
from PIL import ImageSequence
import qrcode
from CuteR import CuteR as cr



def generate_qr_code(data, image,filename,mask_ptn):

    img = image
    txt = data
    output = filename
    ec = qrcode.constants.ERROR_CORRECT_H
    ver = 5
    cont = 1.0
    bri =  1.0
    colr = True
#    colr = False
    pixelate = True
#
    pixelate = False
    if colr :
        rgba = (0,0,0,255)
    else:
        rgba = (0,0,0,255)
        
    output.encode('sjis', errors='ignore').decode('sjis')

 #   frames = cr.produce(txt,img,ver,ec,bri, cont , colr,rgba, pixelate, mask_ptn)
    frames = cr.produce(txt,img,ver,ec,bri, cont , colr,rgba, pixelate)
    if len(frames) == 1 or output.upper()[-3:] != "GIF":
        frames[0].save(output)
    elif len(frames) > 1:
        frames[0].save(output,save_all=True,append_images=frames[1:],duration=100,optimize=True)

def read_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:  # ファイルをUTF-8エンコーディングで読み込み
        return file.readlines()

def main():
    file_path = "b.txt"  # 入力ファイル名を固定化
    lines = read_file(file_path)

    for index, line in enumerate(lines):
        line = line.strip()
        if line:
#
            input_image = f"input_folder/"+(str(index+1).zfill(2))+f".png"  # 出力ファイル名を固定化
#            for ix in range(8):
            for ix in range(1):
#
                output_filename = f"output_folder/"+(str(index+1).zfill(2))+f"-"+line+f"-"+str(ix)+f".png"  # 出力ファイル名を固定化
                generate_qr_code(line,input_image, output_filename,ix)
                print(f"QR code '{output_filename}' generated successfully!")

if __name__ == '__main__':
    main()

マスクパターンを指定したい場合

読み込めない場合もあるので8パターン作れるようにします

CuteR.pyこれを変更します。日本語の文字化けも対応します


def produce(txt,img,ver=5,err_crt = qrcode.constants.ERROR_CORRECT_H,bri = 1.0, cont = 1.0,\
        colourful = False, rgba = (0,0,0,255),pixelate = False, mask_ptn=None):
    if type(img) is Image.Image:
        pass
    elif type(img) is str:
        img = Image.open(img)
    else:
        return []
    frames = [produce_impl(txt,frame.copy(),ver,err_crt,bri,cont,colourful,rgba,pixelate,mask_ptn) for frame in ImageSequence.Iterator(img)]
    return frames

def produce_impl(txt,img,ver=5,err_crt = qrcode.constants.ERROR_CORRECT_H,bri = 1.0, cont = 1.0,\
        colourful = False, rgba = (0,0,0,255),pixelate = False, mask_ptn=None):
    qr = qrcode.QRCode(version = ver,error_correction = err_crt,box_size=3,  mask_pattern=mask_ptn)
    qr.add_data(txt.encode('utf-8'))  # 日本語文字列をUTF-8エンコーディングで処理

以下同じ

Amazing-QR // MyQR

GitHub - x-hw/amazing-qr: 💮 amazing QRCode generator in Python (supporting animated gif) - Python amazing 二维码生成器(支持 gif 动态图片二维码)

pip install amzqr

amzqr Words
[-v {1,2,3,…,40}]
[-l {L,M,Q,H}]
[-n output-filename]
[-d output-directory]
[-p picture_file]
[-c]
[-con contrast]
[-bri brightness]

amzqr https://github.com -p github.jpg [-c] -con 1.5 -bri 1.6

日本語は対応されていません

ArtCoder

https://github.com/SwordHolderSH/ArtCoder

git clone https://github.com/SwordHolderSH/ArtCoder
cd ArtCoder

style_img_path 模様
content_img_path メイン画像
code_img_path QRコードを準備してから

python main.py -style_img_path ./xxxx/xxx.jpg  --content_img_path ./xxxx/xxx.jpg --code_img_path ./xxxx/xxx.jpg --output_dir ./xxxx/

GPUがないパソコンでCPUだけで動かす時

Artcoder.py

vgg = Vgg16(requires_grad=False).cpu()  # vgg16 model
ss_layer = SSlayer(requires_grad=False).cpu()

モデルを自動的にダウンロードします。GPUがないと時間がかかります

たくさんのQRコードを読み込む方法

画像が入った二次元バーコードは読み込めない場合があります。マスクパターンを色々試した時 読むことができる2次元バーコードを調べたい時に使うことができます

http://memo.eightban.com/python/qrread

Quick QR Art

無料の QR コード AI アート ジェネレーター

https://quickqr.art/

Stable Diffusion 二次元バーコード風な画像を作成する

http://memo.eightban.com/stable-diffusion/stable-diffusion-diffusers-qr

美钥二维码

https://meiyaoma.com/

色々な形の二次元バーコードを作成するサイト

https://qrcode.antfu.me/

QR Codes (Classic )
https://quickqr.art/#features

QRコードは(株)デンソーウェーブの登録商標です」

-Python

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.