Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- harfler = r"""abcçdefgğhıijklmnoöprsştuüvyzxqw 0123456789!?.:,_-=;()"\/&%+'*$#"""
- from PIL import Image
- start = '##-start-##'
- end = '##-end-##'
- def embed(text, imageLoc='image.png', saveLoc='out.png'):
- print(len(text))
- print(text[:1000])
- text = '{}{}{}'.format(start,text,end)
- im = Image.open(imageLoc)
- width, height = im.size
- pixColors = im.load()
- hiddenText = calcText(text)
- for h in range(height):
- for w in range(width):
- loc = h*width+w
- if loc < len(text)*2:
- hR, hG, hB = hiddenText[loc]
- R,G,B = pixColors[w,h]
- pixColors[w,h] = R-R%2+hR, G-G%2+hG, B-B%2+hB
- else:
- im.save(saveLoc, 'PNG')
- im.close()
- return loc
- def calcText(text):
- hiddenText = []
- for harf in text:
- hRGB = "{:06b}".format(harfler.find(harf))
- hRGB1, hRGB2 = hRGB[:3], hRGB[3:]
- hiddenText.append(tuple(map(int,tuple(hRGB1))))
- hiddenText.append(tuple(map(int,tuple(hRGB2))))
- return hiddenText
- def readImg(imageLoc='out.png'):
- im = Image.open(imageLoc)
- width, height = im.size
- pixColors = im.load()
- hiddens = []
- for h in range(height):
- for w in range(width):
- R,G,B = pixColors[w,h]
- hiddens.append((R%2, G%2, B%2))
- hiddenLetters = [harfler[int(''.join(map(str,hiddens[i]+
- hiddens[i+1])), 2)] for i in range(0, len(hiddens), 2)]
- hiddenText = ''.join(hiddenLetters)
- startLoc = hiddenText.find(start)+len(start)
- endLoc = hiddenText.find(end)
- hiddenText = hiddenText[startLoc:endLoc]
- return hiddenText
- def onlyCode(text, imageLoc='image.png', saveLoc='OnlyCode.png'):
- print(len(text))
- print(text[:1000])
- text = '{}{}{}'.format(start,text,end)
- im = Image.open(imageLoc)
- width, height = im.size
- pixColors = im.load()
- hiddenText = calcText(text)
- for h in range(height):
- for w in range(width):
- loc = h*width+w
- if loc < len(text)*2:
- R, G, B = hiddenText[loc]
- pixColors[w,h] = R*100, G*100, B*100
- else:
- im.save(saveLoc, 'PNG')
- im.close()
- return loc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement