harsh_jain100
harsh_jain100

Reputation: 13

Best way to convert image,videos to string format

I want to store some of my personal images and videos in an encrypted format and want to develop the python script by myself. As the encryption which I am using requires input in string format what are the most efficient way to convert images and videos to string format?

I have considered using base64 but it won't be a practical and most efficient solution due to its increased size.

Any suggestion on how to achieve this?

Upvotes: 0

Views: 297

Answers (1)

Nishani Kasineshan
Nishani Kasineshan

Reputation: 682

I tried converting an image to string using python's pillow module.

from io import BytesIO
from PIL import Image

image = Image.open(r"*****\naruto.png")#The full path to the image

output = BytesIO()
image.save(output, format="png")
image_as_string = output.getvalue()

print(image_as_string[:20])

My image

Output:

b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x05\xa0'

This worked for me. I am a beginner to programming. So other suggestions will also be helpful.

Upvotes: 1

Related Questions