Skip to content

Instantly share code, notes, and snippets.

@macdrifter
Created October 14, 2012 03:05
Show Gist options
  • Save macdrifter/3887102 to your computer and use it in GitHub Desktop.
Save macdrifter/3887102 to your computer and use it in GitHub Desktop.
imageUpload
import Image, ImageOps, ImageFilter
import ftplib
import console
import clipboard
import datetime
from io import BytesIO
today = datetime.datetime.now()
image = clipboard.get_image()
fileName = console.input_alert("Image Title", "Enter Image File Name")
fileName = fileName+'_'+today.strftime("%Y-%m-%d-%H%M%S") +'.png'
userName = ""
userPass = ""
host = "macdrifter.webfactional.com"
port = 22
urlBase = "http://www.macdrifter.com/uploads/"
remotePath = "/home/macdrifter/webapps/pelican/uploads/"
datePath = today.strftime("%Y/%m/")
# Used to create full remote file path
remoteFilePath = remotePath + datePath
def customSize(img):
w, h = img.size
print 'w: ' + str(w)
print 'h: '+ str(h)
if w > 600:
wsize = 600/float(w)
print 'wsize: '+str(wsize)
hsize = int(float(h)*float(wsize))
print 'hsize: ' + str(hsize)
img = img.resize((600, hsize), Image.ANTIALIAS)
return img
image = customSize(image)
print image.size
image.show()
buffer = BytesIO()
image.save(buffer, 'PNG')
buffer.seek(0)
print remoteFilePath
print fileName
fileURL = urlBase + fileName
ftp = ftplib.FTP(host, userName, userPass)
ftp.cwd(remoteFilePath)
ftp.storbinary('STOR '+fileName, buffer)
ftp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment