Ankit404butfound / PyWhatKit

Send WhatsApp message at certain time and many other things.
MIT License
1.37k stars 298 forks source link

can I send a base64 image instead of the image path? #16

Closed atilamagalhaes4 closed 3 years ago

atilamagalhaes4 commented 4 years ago

b64 = "data:image/jpg;base64,///sdasdasda....." ex: pywhatkit.send_file("+919876543210",b64",15,00).

Ankit404butfound commented 4 years ago

I haven't tested it, but it's worth a try. Although I don't think it's going to work. Let us know.😄

aaryanrr commented 3 years ago

Hey @atilamagalhaes4, You can use this

import base64

img_data = "data:image/jpg;base64,///sdasdasda....."

IMAGE = img_data.split(",")
extension = IMAGE[0].split(";")
with open(f"Picture.{extension[0].split('/')[1]}", "wb") as f:
    f.write(base64.decodebytes(bytes(IMAGE[1], "utf-8")))

The picture will be first written to a file for which the extension will be determined by the data passed in. After that you can use the sendwhats_image function to send this file to the contact. Thanks