from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import urllib.request
import io
import binascii
data = urllib.request.urlopen('http://pastebin.ca/raw/2311595').read()
r_data = binascii.unhexlify(data)
stream = io.BytesIO(r_data)
img = Image.open(stream)
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf",14)
draw.text((0, 220),"This is a test11",(0,255,0),font=font)
draw = ImageDraw.Draw(img)
with open(img,'rb') as in_file: #error on here invalid file:
hex_data = in_file.read()
# Unhexlify the data.
bin_data = binascii.unhexlify(bytes(hex_data))
print(bin_data)
質問
16進数を画像に変換し、画像にテキストを描画した後、画像をバイナリ16進数に変換しますが、ここwith open(img,'rb') as in_file:
で問題があり、imgを16進数に変換する方法は?