徽标的图像不接受用户输入并显示错误属性错误:读取

问题描述 投票:0回答:0

以下代码不接受用户输入,即在 QRcdoe 中心上传用于登录的图像文件。

以下是我的代码:

def add_corners(im, rad):
  circle = Image.new('L', (rad * 2, rad * 2), 0)
  draw = ImageDraw.Draw(circle)
  draw.ellipse((0, 0, rad * 2 - 1, rad * 2 - 1), fill=255)
  alpha=Image.new('L', im.size, 255)
  w, h=im.size
  alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
  alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
  alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
  alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
  im.putalpha(alpha)
  return im

logo_img = st.radio('Do you want to input logo image', ('Yes', 'No'))
if logo_img == 'Yes':
  logoimage = st.file_uploader('Choose the image to upload in the centre of QRcode')
  if logoimage is not None:
    # To read file as bytes:
    logo_file = io.BytesIO(logoimage.getvalue())
    filelogo = Image.open(logo_file)
    # Correcting image
    filelogo = add_corners(filelogo, 100)
  else:
    st.write("No image file attached")
    logoimage = 0

qr_img=qr.make_image(image_factory=StyledPilImage, module_drawer=layout, color_mask=mask_style, embeded_image_path=filelogo)

AttributeError: read
qr_img=qr.make_image(image_factory=StyledPilImage, module_drawer=layout, color_mask=mask_style, embeded_image_path=filelogo)

我期待用户在一些裁剪代码后上传徽标文件将嵌入在二维码的中心。

python image-processing python-imaging-library qr-code
© www.soinside.com 2019 - 2024. All rights reserved.