1 Star 0 Fork 1

Jeremy Lee/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
meme_maker.py 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
Jérôme Krell 提交于 2019-10-10 14:22 . Reformat Code by PyCharm-Community
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Jelmy/Python-1.git
[email protected]:Jelmy/Python-1.git
Jelmy
Python-1
Python-1
master

搜索帮助