pythontelegram-botpy-telegram-bot-api

i want to download images with pytelegrambotapi with good quality , but i cant


I want to download images with pytelegrambotapi with good quality, I use this code, its ok and works, but it download images with bad quality.

@bot.message_handler(content_types=['document', 'photo', 'audio', 'video', 'voice'])
def addfile(message):
    
    if message.photo:
        photo = bot.get_file(message.photo[0].file_id)
        photo_path = photo.file_path
        photo_id = photo.file_id
        photo_type = photo.file_path.split('.')[-1]

        
        file = bot.download_file(photo_path)
        with open(photo_id + "." + photo_type, "wb") as code:
            code.write(file)

what should i do ?


Solution

  • The sent photo undergoes resizing and compression. If you wish to process the original photo as a file, you may manually send it as a document to the bot or utilize the sendDocument feature for that purpose.