Skip to content

Instantly share code, notes, and snippets.

@Te-k Te-k/
Last active May 11, 2016

What would you like to do?
Convert picture to 200 px width and upload it to for LQDN Press Review
#! /usr/bin/python2
import sys
import requests
import tempfile
from PIL import Image
def resize(source_path, dest_path):
"""Resize the image from the source path to the dest"""
png =
width = png.size[0]
height = (png.size[1] * 200) / width
png.resize((200,height), Image.ANTIALIAS).save(dest_path)
def send_lutim(path):
"""Send the image given to lutim"""
url = ''
data = {'format' : 'json'}
files = {'file': open(path, 'rb')}
r =, files=files, data=data)
if r.status_code == 200:
data = r.json()
return True, url + data['msg']['short'], data['msg']['token']
return False, "", ""
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Bad arguments, you should give an image. Quitting...")
f = tempfile.NamedTemporaryFile(delete=False, suffix=".png", prefix="lutim")
dst =
resize(sys.argv[1], dst)
res, url, token = send_lutim(dst)
if res:
print("Successfully uplaoded to")
print("url: %s" % url)
print("Token: %s" % token)
print('Use this : <img src="%s" class="l" />' % url)
print("Failed to uploaded to :'(")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.