2017-02-04 4 views
-1

Dies ist ein Code eines JPG/PNG (ich weiß nicht genau) Here's on google docsWie JPG/PNG in Python dekodieren?

Ich brauche es in Python zu dekodieren Bild zu vervollständigen und zeige es wie die mit Kissen oder so etwas. Kennst du irgendwelche Bibliotheken oder Wege, wie man es entschlüsseln kann? Vielen Dank!

+0

Bitte fügen Sie weitere Informationen hinzu und was Sie bereits versucht haben. – ppasler

+0

Es ist ein JPEG-Bild. (Durch Ausschluss - es ist kein PNG-Bild, wie aus der Kopfzeile ersichtlich ist.) – usr2564301

Antwort

0

(für Python 3)

Wenn das Bild als Binärdatei gespeichert ist, öffnet sie direkt:

import PIL 

# Create Image object 
picture = PIL.Image.open('picture_code.dat') 

#display image 
picture.show() 

# print whether JPEG, PNG, etc. 
print(picture.format) 

Wenn das Bild als Hex in einer Klartextdatei gespeichert wird picture_code.dat ähnlich zu Ihre Google Docs-Link, muss es zuerst in binäre Daten umgewandelt werden:

import binascii 
import PIL 
import io 

# Open plaintext file with hex 
picture_hex = open('picture_code.dat').read() 

# Convert hex to binary data 
picture_bytes = binascii.unhexlify(picture_hex) 

# Convert bytes to stream (file-like object in memory) 
picture_stream = io.BytesIO(picture_bytes) 

# Create Image object 
picture = PIL.Image.open(picture_stream) 

#display image 
picture.show() 

# print whether JPEG, PNG, etc. 
print(picture.format)