Skip to content
Permalink
Browse files

Further document automatic photo resizing

  • Loading branch information...
Lonami committed Feb 13, 2019
1 parent fd24f70 commit 5c85f830bdd84f1e82cca1d1b20d262667837206
Showing with 8 additions and 1 deletion.
  1. +1 −0 optional-requirements.txt
  2. +6 −0 telethon/client/uploads.py
  3. +1 −1 telethon_generator/data/errors.csv
@@ -1,3 +1,4 @@
cryptg
pysocks
hachoir3
pillow
@@ -31,6 +31,7 @@ def __eq__(self, other):


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.
@@ -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

0 comments on commit 5c85f83

Please sign in to comment.
You can’t perform that action at this time.