Python Script to convert Image into Byte array

前端 未结 4 593
予麋鹿
予麋鹿 2020-12-08 06:36

I am writing a Python script where I want to do bulk photo upload. I want to read an Image and convert it into a byte array. Any suggestions would be greatly appreciated.

4条回答
  •  生来不讨喜
    2020-12-08 06:56

    with BytesIO() as output:
        from PIL import Image
        with Image.open(filename) as img:
            img.convert('RGB').save(output, 'BMP')                
        data = output.getvalue()[14:]
    

    I just use this for add a image to clipboard in windows.

提交回复
热议问题