Skip to content

Commit

Permalink
update example for a post involving image editing
Browse files Browse the repository at this point in the history
Python 2 support was dropped from Twython, thanks!
In Python3 we actually have to use BytesIO, see python-pillow/Pillow#2205
  • Loading branch information
kannes committed Jul 17, 2020
1 parent 02fb356 commit 33f46c0
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions docs/usage/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,10 @@ with a status update.

.. code-block:: python
# Assume you are working with a JPEG
# Assuming that you are working with a JPEG
from PIL import Image
try:
# Python 3
from io import StringIO
except ImportError:
# Python 2
from StringIO import StringIO
from io import BytesIO
photo = Image.open('/path/to/file/image.jpg')
Expand All @@ -76,14 +71,13 @@ with a status update.
height = int((float(photo.size[1]) * float(wpercent)))
photo = photo.resize((basewidth, height), Image.ANTIALIAS)
image_io = StringIO.StringIO()
image_io = BytesIO()
photo.save(image_io, format='JPEG')
# If you do not seek(0), the image will be at the end of the file and
# unable to be read
image_io.seek(0)
response = twitter.upload_media(media=image_io)
twitter.update_status(status='Checkout this cool image!', media_ids=[response['media_id']])
Expand Down

0 comments on commit 33f46c0

Please sign in to comment.