Last active
November 2, 2022 13:55
-
-
Save SahilC/e02b134dedcff1d016843c6bed55fcd1 to your computer and use it in GitHub Desktop.
Due to recent events, I've decided to make this script to help you get to know me better. Please run the script to find out more.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Due to recent events, I've made this script to help you get to know me better. | |
Please run the script to find out more. | |
''' | |
import base64 | |
# pip install pillow | |
# pip install requests | |
from PIL import Image, ImageDraw, ImageFont | |
import numpy as np | |
import requests | |
end_of_message = "0100100101010101010101100100111101010010010001010011100101000111010101000101010101010110010101000101010100110000010001100100100001010010010100110100010100111101" | |
def get_image(fname): | |
return Image.open(fname) | |
def get_np_from_image(img): | |
np_array = np.array(img) | |
return np.reshape(np_array, (np_array.shape[0] * np_array.shape[1] * np_array.shape[2])) | |
def decode_message_from_bytestring(bytestring): | |
bytestring = bytestring.split(end_of_message)[0] | |
message = int(bytestring, 2).to_bytes(len(bytestring) // 8, byteorder='big') | |
message = base64.decodebytes(message).decode("utf8") | |
return message | |
def decode_pixels(pixels): | |
bytestring = ''.join([str(c % 2) for c in pixels]) | |
message = decode_message_from_bytestring(bytestring) | |
return message | |
def main(): | |
url = 'https://raw.githubusercontent.com/SahilC/sahilc.github.io/master/img/profile.png' | |
in_image = requests.get(url, stream=True).raw | |
img = get_image(in_image) | |
pixels = get_np_from_image(img) | |
text = decode_pixels(pixels) | |
fnt = ImageFont.truetype("arial", 16) | |
draw = ImageDraw.Draw(img) | |
draw.multiline_text((img.width / 6, img.height / 10), text, font=fnt, fill=(232, 25, 25), stroke_width=1) | |
img.show() | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment