/
rnekrasov
/
Python
Обзор
Документация
Войти
/
rnekrasov
/
Python
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
meme_maker.py
55 строк
2 KB
slowy07
refactor: clean code
30 янв 2022, 04:33
30 янв 2022, 04:33
f0af0c4
Код
Авторство
О чём код?
import sys from PIL import ImageDraw, ImageFont, Image def input_par(): print("Enter the text to insert in image: ") text = str(input()) print("Enter the desired size of the text: ") size = int(input()) print("Enter the color for the text(r, g, b): ") color_value = [int(i) for i in input().split(" ")] return text, size, color_value pass def main(): path_to_image = sys.argv[1] image_file = Image.open(path_to_image + ".jpg") image_file = image_file.convert("RGBA") pixdata = image_file.load() print(image_file.size) text, size, color_value = input_par() # Font path is given as -->( " Path to your desired font " ) font = ImageFont.truetype("C:\\Windows\\Fonts\\Arial.ttf", size=size) # If the color of the text is not equal to white,then change the background to be white if (color_value[0] and color_value[1] and color_value[2]) != 255: for y in range(100): for x in range(100): pixdata[x, y] = (255, 255, 255, 255) # If the text color is white then the background is said to be black else: for y in range(100): for x in range(100): pixdata[x, y] = (0, 0, 0, 255) image_file.show() # Drawing text on the picture draw = ImageDraw.Draw(image_file) draw.text( (0, 2300), text, (color_value[0], color_value[1], color_value[2]), font=font ) draw = ImageDraw.Draw(image_file) print("Enter the file name: ") file_name = str(input()) image_file.save(file_name + ".jpg") pass if __name__ == "__main__": main()