Advertisement
Guest User

Код обработки

a guest
Jul 16th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. @bot.message_handler(content_types=['text', 'photo'])
  2. def handle_docs(message):
  3.     if message.text.lower().split(' ')[0] == 'обработка':
  4.         print('doshlo')
  5.         try:
  6.             factor=message.text.split(' ')[2]
  7.         except:
  8.             try:
  9.                 mode=message.text.split(' ')[1]
  10.                 if is_number(mode) == 1:
  11.                     mode = int(mode)
  12.                     if mode == 0:
  13.                         print(mode)
  14.                         bot.reply_to(message,"Отправьте фотографию")
  15.                         bot.register_next_step_handler(message, photo0)
  16.             except:
  17.                 bot.reply_to(message,"Вы не написали как обрабатывать фото")    
  18. def photo0(message):
  19.     print('est')
  20.     file_info = bot.get_file(message.photo[len(message.photo)-1].file_id)
  21.     downloaded_file = bot.download_file(file_info.file_path)
  22.     src='/sdcard/'+file_info.file_path;
  23.     with open(src, 'wb') as new_file:
  24.         new_file.write(downloaded_file)
  25.         print(file_info.file_path)
  26.         bot.reply_to(message,"Фото сохранено")
  27.         w=file_info.file_path
  28.         w1=w[-11:]
  29.         print(w1)
  30.         image = Image.open(w1)
  31.         draw = ImageDraw.Draw(image)
  32.         width = image.size[0]
  33.         height = image.size[1]
  34.         pix = image.load()
  35.         for i in range(width):
  36.             for j in range(height):
  37.                 a = pix[i, j][0]
  38.                 b = pix[i, j][1]
  39.                 c = pix[i, j][2]
  40.                 S = (a + b + c) // 3
  41.                 draw.point((i, j), (S, S, S))
  42.         image.save("photo1.jpg", "JPEG")
  43.         del draw
  44.         img = open('photo1.jpg', 'rb')
  45.         bot.send_photo(message.chat.id,img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement