Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- print("This is a program to format a text file so it resembles an image by Benedikt Vilji Magnússon")
- text_file_name = input("Text file to use: ")
- image_file_name = input("Image to follow after: ")
- ww, wh = input("Width and height of the outcoming immage in letters and lines (w/h): ").split(" ")
- with open(text_file_name, 'r') as file:
- data = file.read().replace('\n', '')
- img = cv2.imread(image_file_name, cv2.IMREAD_GRAYSCALE)
- img2 = cv2.resize(img, (int(ww), int(wh)))
- w, h = img2.shape[0], img2.shape[1]
- current_index = 0
- fins = ""
- for i in range(w):
- for j in range(h):
- if img2[i, j] < 200:
- fins += data[current_index]
- current_index += 1;
- else:
- fins += " "
- fins += "\n"
- print(fins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement