Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add caption to downloaded images #110
Instaloader does not modify the downloaded JPEG file. However, you could combine it with an imaging library such as Pillow or PIL to render the Post.caption on pictures. An approach could be
from io import BytesIO from requests import get from PIL import Image, ImageDraw from instaloader import * L = Instaloader() # Load Post instance post = load_structure_from_file(L.context, '2017-10-01_18-53-03_UTC.json.xz') # or post = Post.from_shortcode(L.context, SHORTCODE) # Render caption image = Image.open(BytesIO(get(post.url).content)) draw = ImageDraw.Draw(image) draw.text((300,100), post.caption.encode('latin1', errors='ignore')) # Save image image.save('test.jpg')
However, this is just an approach. See e.g. https://pillow.readthedocs.io/en/5.1.x/index.html for how to modify images with Python (there are plenty more libraries tough). Instaloader exports a picture's URL as Post.url and its caption as Post.caption.