Python base 64 for image

Asked

Viewed 44 times

1

Personal I’m taking 1 photo from the database but it’s coming as base 64 , that I need it to turn image again to be able to locate on the screen , how do I turn the base 64 into Bites again? I tried to make a mistake

agua = str(dataBase.read_fotos("foto", "agua", "1"))
agua = agua[4:]
agua = agua[:-4]
img_agua = base64.b64decode(agua)
rod = str(dataBase.read_fotos("foto", "vara", "1"))
rod = rod[4:]
rod = rod[:-4]
img_rod = base64.b64decode(rod)

# -------------------------------encontrar posições--------------------
water_position = pyautogui.locateOnScreen(img_agua)
rod_position = pyautogui.locateOnScreen(img_rod)

inserir a descrição da imagem aqui

AttributeError: 'bytes' object has no attribute 'mode'

1 answer

1

The PIL library should solve:

import PIL.Image as Image

image = Image.open(io.BytesIO(bytes))

Where bytes is the variable that has the bytes of the image.

I hope it helps

  • right, but this variable with bytes, is encoded in base 64, what I needed was to switch to bytes, you think Pil would work for my case ?

  • It would not be the case to use bytearray(sua_variavel_base_64) ?

  • I tried this way he gave the following error

  • img_agua = bytearray(agua) Typeerror: string argument without an encoding

  • Try bytes(sua_variavel, encoding='utf8'). If it doesn’t work, put the content of your variable in a gist and update your post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.