Editorial Workflows

FTP Image Upload

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Worklow uses iOS image selector to pick image from Photos, resize the image to a more web friendly size, upload via FTP to your site, then insert image into Editorial document.

Shared by: Jason Verly (@MyGeekDaddy)

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# Script uses iOS Photos selector to select image to be uploaded.

import clipboard
import Image
import console
import photos


console.alert("Pick Image", "Click 'Select' to use Photos image selector", "Select")

img_1 = photos.pick_image(show_albums=True)
clipboard.set_image((img_1), format='png')

print "\n\n Image set to clipboard"
Get Current File Name ?
Include Folder
Include Extension
Set Variable ?
Variable Name
Run Python Script ?
Source Code
# Python script to upload image from clipboard to ftp via Editorial WF
import workflow
import keychain
import pickle
import Image, ImageOps, ImageFilter
import ftplib
import console
import clipboard
import datetime
from io import BytesIO
import urllib

today = datetime.datetime.now()
image = clipboard.get_image()

#Pulls document title from variable in previous WF step
imgtitle = workflow.get_variable('DocTitleVar')

# Double .replace used to make image name just alphanumeric and underscores
imgtitle = imgtitle.replace (" ", "_")
imgtitle = imgtitle.replace("-_","")
imgtitle = imgtitle.encode('ascii', 'ignore')

imgname = '_img_'+ imgtitle + '_' + today.strftime("%Y_%m_%d_%H%M%S") +'.png'

# Uncomment this line to reset stored password
#keychain.delete_password('mygeekdaddy', 'editorial')
login = keychain.get_password('mygeekdaddy', 'editorial')
if login is not None:
	username, passwd = pickle.loads(login)
	username, passwd = console.login_alert('FTPS Login Needed', 'No login credentials found.')
	pickle_token = pickle.dumps((username, passwd))
	keychain.set_password('mygeekdaddy', 'editorial', pickle_token)

# Change host/port/etc to values for your website
host = "acme.net"
port = 99
baseURL = "http://image.acme.net/"

# folder on ftp site where image will be saved
imgfolder = "/share/"

# Routine used to resize image
def customSize(img):
    w, h = img.size
    print 'w: ' + str(w)
    print 'h: '+ str(h)
# Adjust number in next line to image width.
# Currently set to 1000 pixels
    if w > 1000:
        wsize = 1000/float(w)
        print 'wsize: '+str(wsize)
        hsize = int(float(h)*float(wsize))
        print 'hsize: ' + str(hsize)

        img = img.resize((1000, hsize), Image.ANTIALIAS)
    return img

image = customSize(image)

buffer = BytesIO()
image.save(buffer, 'PNG')

imgURL = urllib.quote(imgname)

# FTP upload routine
	ftp = ftplib.FTP(host, username, passwd)	
	ftp.storbinary('STOR '+ imgname, buffer)
except Exception, e:
	print e
	console.alert('Error', e)

# If image stored in subdomain (image.acme.org) use this one
imageLink = baseURL + imgURL

# If image stored in folder (acme.org/image) use this one
#imageLink = baseURL + imgfolder + imgURL

print image.size
print imgname
print imageLink
print ''
print 'FTP upload complete.'

Replace Selected Text ?
Replacement Text
<figure><a href="Clipboard"><img src="Clipboard" title="" id="" style="display:block; margin-left:auto; margin-right:auto; width:600px;" class="aligncenter size-full" /></img></a></figure>