-
-
Save taddeimania/301117b5e21639ef38e7 to your computer and use it in GitHub Desktop.
Show this file as an image
This file contains 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
from PIL import Image | |
from math import sqrt | |
def get_color_value(contents, loc): | |
try: | |
return ord(contents[loc]) | |
except IndexError: | |
return 0 | |
def get_color_triplet(contents, loc): | |
red = get_color_value(contents, loc) | |
green = get_color_value(contents, loc + 1) | |
blue = get_color_value(contents, loc + 2) | |
return red, green, blue | |
def main(): | |
contents = open(__file__).read() | |
size_of = len(contents) | |
square_of = sqrt(size_of) | |
color_values = [] | |
loc = 0 | |
for bit in contents: | |
color_group = get_color_triplet(contents, loc) | |
color_values.append(color_group) | |
loc += 3 | |
rows = int(square_of/2) | |
img = Image.new('RGB', (int((size_of/3) / rows), rows), "black") | |
pixels = img.load() | |
pixel_loc = 0 | |
for i in range(img.size[0]): | |
for j in range(img.size[1]): | |
pixels[i, j] = color_values[pixel_loc] | |
pixel_loc += 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