Editorial Workflows

Insert Photo...

unlisted 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: Saves an image from the camera roll or takes a picture as a jpeg file in the current document's directory, and inserts a markdown image reference.

Shared by: Macdrifter

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
A document has to be open... ?
Run the block if
File Name
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
ON
Message
No Document Selected
…End If
Show Alert ?
Title
Insert a photo or image...
Message
Button 1
Photo
Output Value
photo
Button 2
Image
Output Value
image
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Run Python Script ?
Source Code
#coding: utf-8
import photos
import workflow
import console
import editor
import urllib
import os
import io
from time import gmtime, strftime


timestamp=strftime("%Y-%m-%d %H%M%S ", gmtime())

input = workflow.get_input()

if input == "photo":
	img = photos.capture_image()
else:
	img = photos.pick_image()
if not img:
	workflow.stop()

doc_path = editor.get_path()
doc_dir, fn = os.path.split(doc_path)
default_name = timestamp+' Image'
i = 1
while True:
	if not os.path.exists(os.path.join(doc_dir, default_name + '.jpg')):
		break
	default_name = timestamp+'Image_' + str(i)
	i += 1

root, rel_doc_path = editor.to_relative_path(editor.get_path())
filename = console.input_alert('File Name', 'The image will be saved in the Images folder.', default_name + '.jpg', 'Save')
if not filename:
	workflow.stop()
img_data = io.BytesIO()
img.save(img_data, 'jpeg')
rel_doc_dir, fn = os.path.split(rel_doc_path)
dest_path = os.path.join('Images', filename)
url_file = urllib.quote(dest_path)
editor.set_file_contents(dest_path, img_data.getvalue(), root)
workflow.set_output(url_file)
Replace Selected Text ?
Replacement Text
![Image](Input)