Merge pull request #537 from kannes/patch-1
update example for a post involving image editing
This commit is contained in:
commit
8e004f5d89
1 changed files with 3 additions and 9 deletions
|
|
@ -59,15 +59,10 @@ with a status update.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
# Assume you are working with a JPEG
|
# Assuming that you are working with a JPEG
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
try:
|
from io import BytesIO
|
||||||
# Python 3
|
|
||||||
from io import StringIO
|
|
||||||
except ImportError:
|
|
||||||
# Python 2
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
photo = Image.open('/path/to/file/image.jpg')
|
photo = Image.open('/path/to/file/image.jpg')
|
||||||
|
|
||||||
|
|
@ -76,14 +71,13 @@ with a status update.
|
||||||
height = int((float(photo.size[1]) * float(wpercent)))
|
height = int((float(photo.size[1]) * float(wpercent)))
|
||||||
photo = photo.resize((basewidth, height), Image.ANTIALIAS)
|
photo = photo.resize((basewidth, height), Image.ANTIALIAS)
|
||||||
|
|
||||||
image_io = StringIO.StringIO()
|
image_io = BytesIO()
|
||||||
photo.save(image_io, format='JPEG')
|
photo.save(image_io, format='JPEG')
|
||||||
|
|
||||||
# If you do not seek(0), the image will be at the end of the file and
|
# If you do not seek(0), the image will be at the end of the file and
|
||||||
# unable to be read
|
# unable to be read
|
||||||
image_io.seek(0)
|
image_io.seek(0)
|
||||||
|
|
||||||
|
|
||||||
response = twitter.upload_media(media=image_io)
|
response = twitter.upload_media(media=image_io)
|
||||||
twitter.update_status(status='Checkout this cool image!', media_ids=[response['media_id']])
|
twitter.update_status(status='Checkout this cool image!', media_ids=[response['media_id']])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue