def photoshop(image_path):
img = Image.open(image_path).convert("RGBA")
new_path = image_path + '_' + '.png'
txt = Image.new('RGBA', img.size, (255,255,255,0))
#Creating Text
font = ImageFont.truetype("AldrichRegular.ttf", 82)
#Creating Draw Object
d = ImageDraw.Draw(txt)
#Positioning Text
width, height = img.size
textwidth, textheight = d.textsize(text, font)
x=width/2-textwidth/2
y=x-200
#Applying Text
d.text((x,y), text, fill=(255,255,255, 125), font=font)
print('photoshop')
global watermarked1
watermarked1 = Image.alpha_composite(img, txt)
watermarked1.save(new_path)
return new_path
def get_text(message):
global text;
text = message.text
texti = dict()
def aug(message):
print(message.photo[:-1])
texti[str(message.chat.id)] = []
try:
file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'D:/Python/TeleGramWaterMurkBot/filez/' + file_info.file_path
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message,"Фото добавлено")
texti[str(message.chat.id)].append(src)
bot.send_message(message.chat.id, 'Введите текст')
bot.register_next_step_handler(message, get_text)
except Exception as e:
bot.reply_to(message,"ОшибОчка")
bot.reply_to(message, e )
print('img: ', texti)
text_img = ''
print(text)
if (len(texti[str(message.chat.id)]) == 1):
text_img = photoshop(texti[str(message.chat.id)][0])
texti[str(message.chat.id)].append(text_img)
bot.send_photo(message.chat.id, open(text_img, 'rb'))
bot.send_photo(message.chat.id, watermarked1)
print('doneeee')
Вот часть кода , функция aug принимает фото , get text принимает текст и photoshop добавляет на фото текст вроде работает , но появляется ошибка WaterBot1.py - мой бот
Traceback (most recent call last):
File "D:\Python\TeleGramWaterMurkBot\WaterBot1.py", line 173, in
bot.polling(none_stop=True)
File "D:\Python\Scripts\lib\site-packages\telebot\__init__.py", line 621, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
File "D:\Python\Scripts\lib\site-packages\telebot\__init__.py", line 695, in __threaded_polling
raise e
File "D:\Python\Scripts\lib\site-packages\telebot\__init__.py", line 651, in __threaded_polling
self.worker_pool.raise_exceptions()
File "D:\Python\Scripts\lib\site-packages\telebot\util.py", line 147, in raise_exceptions
raise self.exception_info
File "D:\Python\Scripts\lib\site-packages\telebot\util.py", line 93, in run
task(*args, **kwargs)
File "D:\Python\TeleGramWaterMurkBot\WaterBot1.py", line 162, in auf
text_img = photoshop(texti[str(message.chat.id)][0])
File "D:\Python\TeleGramWaterMurkBot\WaterBot1.py", line 111, in photoshop
font = ImageFont.truetype("AldrichRegular.ttf", 82)
File "D:\Python\Scripts\lib\site-packages\PIL\ImageFont.py", line 959, in truetype
return freetype(font)
File "D:\Python\Scripts\lib\site-packages\PIL\ImageFont.py", line 956, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "D:\Python\Scripts\lib\site-packages\PIL\ImageFont.py", line 247, in __init__
self.font = core.getfont(
OSError: cannot open resource