필요 라이브러리 

qrcode -qr코드 생성

https://pypi.org/project/qrcode/

reportlab - 대량생성한 qr코드 이미지를 하나의 pdf 로 만들어줌

https://pypi.org/project/reportlab/

 

c = canvas.Canvas('/Users/thomas/Desktop/coupon/coupons.pdf')
y = 0
x = 0
for i in range(0, 100):
        uuid1 = shortuuid.uuid()
        qr = qrcode.QRCode(
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_H,
            box_size=5,
            border=3,
        )
        qr.add_data(uuid1)
        qr.make(fit=True)
        img = qr.make_image(fill_color=(255, 126, 54), back_color="white").convert('RGB')
        
        # 중앙에 이미지 추가를 원할시 
        # face = Image.open('/Users/thomas/Desktop/images/Image.jpg')
        # face.thumbnail((60, 60))
        # pos = ((img.size[0] - face.size[0]) // 2, (img.size[1] - face.size[1]) // 2)
        #
        # img.paste(face, pos)
        
       	img.save(f"/Users/thomas/Desktop/coupon/qrcode-쿠폰{i}.png")
        
        x += 1
        if i % 10 == 0:
            y += 1
            x = 1
            
        c.drawImage(f'/Users/thomas/Desktop/coupon/qrcode-쿠폰{i}.png', x * 1.5 * cm, y * 1.5 * cm, 1.5 * cm,1.5 * cm)
        
        
c.showPage()
c.save()

포샵에서 열면 

 

참고:

https://stackoverflow.com/questions/26474277/grouping-images-to-one-image

반응형

+ Recent posts