i'm new in programming so i have some question about converting string to color image.
i have one data , it consists of Hex String, like a fff2f3..... i want to convert this file to png like this.
i can convert the hex data to png image through this site
but i don't know how to convert the hex data to png image using python code
but i tried to use Image.frombytes('RGB',(1600,1059),hex_str)
but
i don't know image size , so i cannot use this method.
so My question is how can i convert this hex data to image using python code
please give me some advise , thank you :)
Reading the hexadecimal string into a bytes object, and then writing that binary into a .png
file can be done like this:
with open('binary_file') as file:
data = file.read()
data = bytes.fromhex(data[2:])
with open('image.png', 'wb') as file:
file.write(data)
And produces this result, keep in mind it is corrupted:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With