Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

[BUG] Aspect ratio should be rounded #1413

@leon-wbr

Description

@leon-wbr

Example file

def upload_picture(bot):  # Automatically post a pic in 'pics' folder
    pics = glob(pics_path + "*.jpg")
    pics = sorted(pics)
    try:
        for pic in pics:
            if pic in posted_pic_list:
                continue

            pic_name = pic[:-4]
            caption_file = pic_name + ".txt"

            if os.path.isfile(caption_file):
                with open(caption_file, "r") as file:
                    caption = file.read() + "\n\n" + config.FOLLOW_MESSAGE + "\n" + config.PICS_HASHTAGS
            else:
                caption = config.FOLLOW_MESSAGE + "\n" + config.PICS_HASHTAGS

            bot.upload_photo(pic, caption=caption)
            if bot.api.last_response.status_code != 200:
                print(bot.api.last_response)
                break

            if pic not in posted_pic_list:
                posted_pic_list.append(pic)
                with open(config.POSTED_PICS_FILE, "a") as f:
                    f.write(pic + "\n")
                bot.logger.info("Succesfully uploaded: " + pic)
                break
    except Exception as e:
        bot.logger.error("Couldn't upload pic")
        bot.logger.error(str(e))

Describe the bug

Any file with exact 4:5 ratio won't be uploaded because its aspect ratio is 0.7998 instead of 0.8. This is clearly a rounding issue, any of those pictures can be uploaded without issues on the phone.

Log

FOUND: w:1638 h:2048 r:0.7998046875
2020-04-09 22:34:40,710 - ERROR - Photo does not have a compatible photo aspect ratio.
2020-04-09 22:34:40,711 - INFO - Photo 'pics\IMG_4290.jpg' is not uploaded.
2020-04-09 22:34:40,713 - INFO - Succesfully uploaded: pics\IMG_4290.jpg
2020-04-09 22:34:40,716 - INFO - Total requests: 11

To Reproduce

Simply try uploading an image with exactly 4:5 ratio.

Expected behavior

Upload the image (or maybe even crop if necessary?)

Additional context

Version

Python version (python -v):

Operating Systeem: Win/Linux/MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions