求解 Python 如何以环形拼接图片 [附代码]

想附近效果图但是上传一直在转圈圈

from pystrich.datamatrix import DataMatrixEncoder
from PIL import Image, ImageDraw, ImageFont
import math

# Create image background 創建底圖 mm(3.3pixel per mm)
baseX = 1000
baseY = 800

baseX_px = int(baseX*3.3)
baseY_px = int(baseY*3.3)
base = Image.new("RGB", (baseX_px,baseY_px), (255,255,255))

myFont = ImageFont.truetype("/System/Library/Fonts/AppleSDGothicNeo.ttc", 8)
drawAvatar = ImageDraw.Draw(base)

# initial barcode content number 初始條碼號碼
sn = 11920
x,y,z = 0,0,0
for y in range(0,1):
    for x in range(0,100):
        x += 1
        y += 1
        # z -= 2
        a = 0 + math.sin(x * (math.pi / 180)) * 50
        b = 0 - math.cos(y * (math.pi / 180)) * 50
        encoder = DataMatrixEncoder("{:0>6}".format(sn))
        encoder.save("temp.png")
        print("{:0>6}".format(sn))
        im = Image.open("temp.png")
        base.paste(im.rotate(z,center=(a,b)),(66*x,83*y))
        drawAvatar.text([x*66+14, y*83+70],"{:0>6}".format(sn), fill=(128,128,128), font=myFont)
        sn += 2
    #drawAvatar.line([0, y*83 , baseX_px, y*83],fill = (192, 192, 192), width = 1)

base.save("DataMatrixComposited.png",dpi=(84,84))
base.show()
print("total length in mm:")
print(str(sn*20))
Jason990420
最佳答案
from pystrich.datamatrix import DataMatrixEncoder
from PIL import Image, ImageDraw, ImageFont
import math

sn = 11920
myFont = ImageFont.truetype("/System/Library/Fonts/AppleSDGothicNeo.ttc", 8)

width, height = size = (1280, 1280)
im = Image.new(mode="RGB", size=size, color='white')

for a in range(-900, 50, 50):

    encoder = DataMatrixEncoder("{:0>6}".format(sn))
    encoder.save("temp.png")
    QR_Code = Image.open("temp.png")
    w, h = QR_Code.size
    icon_QR = Image.new(size=(w, h+8), mode='RGB', color='white')
    icon_QR.paste(QR_Code, (0, 0))
    drawAvatar = ImageDraw.Draw(icon_QR)
    drawAvatar.text([20, h],"{:0>6}".format(sn), fill='black', font=myFont)

    x = int(1200 * math.cos(a * math.pi / 1800))
    y = int(1200 * math.sin(a * math.pi / 1800))
    im.paste(icon_QR.rotate((900+a)//10, resample=Image.BICUBIC, expand=True,
        fillcolor='white'), (x, -y))

    sn += 2

im.save("DataMatrixComposited.png",dpi=(84,84))
3年前 评论
讨论数量: 2
Jason990420

看起來代碼有几個問題, 但是看不出來你想畫什麼二維碼圖, 能說清楚嗎?

3年前 评论
Jason990420

不知道你要什么, 所以随便写了一个

from pystrich.datamatrix import DataMatrixEncoder
from PIL import Image, ImageDraw, ImageFont
import math

baseX = 1000
baseY = 800
baseX_px = int(baseX*3.3)
baseY_px = int(baseY*3.3)
base = Image.new("RGB", (baseX_px,baseY_px), (255,255,255))

myFont = ImageFont.truetype("/System/Library/Fonts/AppleSDGothicNeo.ttc", 8)
drawAvatar = ImageDraw.Draw(base)
sn = 11920
for a in range(0, 3600, 50):
    x = int(1200 * math.cos(a * math.pi / 1800))
    y = int(1200 * math.sin(a * math.pi / 1800))
    encoder = DataMatrixEncoder("{:0>6}".format(sn))
    encoder.save("temp.png")
    im = Image.open("temp.png")
    base.paste(im.rotate(90-a, fillcolor='white'), (x+1650, y+1320))
    drawAvatar.text([x+1685, y+1390],"{:0>6}".format(sn), fill=(128,128,128), font=myFont)
    sn += 2

base.save("DataMatrixComposited.png",dpi=(84,84))
base.show()
3年前 评论
yuyuu (楼主) 3年前
klsjnfkjdn 3年前
yuyuu (楼主) 3年前
yuyuu (楼主) 3年前
Jason990420
from pystrich.datamatrix import DataMatrixEncoder
from PIL import Image, ImageDraw, ImageFont
import math

sn = 11920
myFont = ImageFont.truetype("/System/Library/Fonts/AppleSDGothicNeo.ttc", 8)

width, height = size = (1280, 1280)
im = Image.new(mode="RGB", size=size, color='white')

for a in range(-900, 50, 50):

    encoder = DataMatrixEncoder("{:0>6}".format(sn))
    encoder.save("temp.png")
    QR_Code = Image.open("temp.png")
    w, h = QR_Code.size
    icon_QR = Image.new(size=(w, h+8), mode='RGB', color='white')
    icon_QR.paste(QR_Code, (0, 0))
    drawAvatar = ImageDraw.Draw(icon_QR)
    drawAvatar.text([20, h],"{:0>6}".format(sn), fill='black', font=myFont)

    x = int(1200 * math.cos(a * math.pi / 1800))
    y = int(1200 * math.sin(a * math.pi / 1800))
    im.paste(icon_QR.rotate((900+a)//10, resample=Image.BICUBIC, expand=True,
        fillcolor='white'), (x, -y))

    sn += 2

im.save("DataMatrixComposited.png",dpi=(84,84))
3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!