Further document automatic photo resizing

This commit is contained in:
Lonami Exo 2019-02-13 09:58:02 +01:00
parent fd24f7087e
commit 5c85f830bd
3 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,4 @@
cryptg
pysocks
hachoir3
pillow

View File

@ -31,6 +31,7 @@ class _CacheType:
def _resize_photo_if_needed(file, is_image, width=1280, height=1280):
# https://github.com/telegramdesktop/tdesktop/blob/12905f0dcb9d513378e7db11989455a1b764ef75/Telegram/SourceFiles/boxes/photo_crop_box.cpp#L254
if (not is_image
or PIL is None
or (isinstance(file, io.IOBase) and not file.seekable())):
@ -164,6 +165,11 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
If the ``hachoir3`` package (``hachoir`` module) is installed,
it will be used to determine metadata from audio and video files.
If the `pillow` package is installed and you are sending a photo,
it will be resized to fit within the maximum dimensions allowed
by Telegram to avoid ``errors.PhotoInvalidDimensionsError``. This
cannot be done if you are sending :tl:`InputFile`, however.
Returns:
The `telethon.tl.custom.message.Message` (or messages) containing
the sent file, or messages if a list of them was passed.

View File

@ -171,7 +171,7 @@ PHOTO_CONTENT_URL_EMPTY,400,The content from the URL used as a photo appears to
PHOTO_CROP_SIZE_SMALL,400,Photo is too small
PHOTO_EXT_INVALID,400,The extension of the photo is invalid
PHOTO_INVALID,400,Photo invalid
PHOTO_INVALID_DIMENSIONS,400,The photo dimensions are invalid
PHOTO_INVALID_DIMENSIONS,400,The photo dimensions are invalid (hint: `pip install pillow` for `send_file` to resize images)
PHOTO_SAVE_FILE_INVALID,400,The photo you tried to send cannot be saved by Telegram. A reason may be that it exceeds 10MB. Try resizing it locally
PHOTO_THUMB_URL_EMPTY,400,The URL used as a thumbnail appears to be empty or has caused another HTTP error
PIN_RESTRICTED,400,You can't pin messages in private chats with other people

1 name codes description
171 PHOTO_CROP_SIZE_SMALL 400 Photo is too small
172 PHOTO_EXT_INVALID 400 The extension of the photo is invalid
173 PHOTO_INVALID 400 Photo invalid
174 PHOTO_INVALID_DIMENSIONS 400 The photo dimensions are invalid The photo dimensions are invalid (hint: `pip install pillow` for `send_file` to resize images)
175 PHOTO_SAVE_FILE_INVALID 400 The photo you tried to send cannot be saved by Telegram. A reason may be that it exceeds 10MB. Try resizing it locally
176 PHOTO_THUMB_URL_EMPTY 400 The URL used as a thumbnail appears to be empty or has caused another HTTP error
177 PIN_RESTRICTED 400 You can't pin messages in private chats with other people