我使用PIL打開圖像以提取幾位並將它們寫入字符串。它應該是,這個代碼將過濾除了那些,有代碼(R < = 1 & & G < = 1 & & B < = 1),並拿走每種顏色的最後一位。問題是它不起作用。PIL image.open()不適用於我的.png
from PIL import Image
def extract_bits(color, bitmask):
bitmask_len = len(bin(bitmask)[2:])
extracted_bits = bin(color & bitmask)[2:]
extracted_bits = '0' * (bitmask_len - len(extracted_bits)) + extracted_bits
return extracted_bits
if __name__ == '__main__':
img = Image.open('IMG_0707png')
pixels = list(img.getdata())
bits = ''
for i in range(0, len(pixels), 1):
r = pixels[i][0]
g = pixels[i][1]
b = pixels[i][2]
if not (r <= 1 and g <= 1 and b <= 1): continue
bits += extract_bits(r, 0x1)
bits += extract_bits(g, 0x1)
bits += extract_bits(b, 0x1)
bits += '0' * (8 - len(bits) % 8)
text = ''
for i in range(0, len(bits), 8):
text += chr(int(bits[i:i+8], 2))
print text
我環顧這個問題,發現解決方案在我的情況下不起作用。 img = Image.open(open('IMG_0707.png', 'rb'))
在這兩種情況下,我得到
File "<stdin>, line 1, in <module>"
File "<string>" line11, im <module>
File "c:\python27\lib\site-packages\PIL\Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
我也試過,沒有運氣指定確切路徑。
img = Image.open(open("IMG_0707.png", 'rb'))
img = Image.open(open("c:\python27\IMG_0707.png", 'rb'))
img = Image.open(open("c:/python27/IMG_0707.png", 'rb'))
依此類推。我會很感激任何幫助。 Image, im trying to open
非常感謝。將嘗試另一種方式解決CTF挑戰。 –