Editorial Workflows

Upload & Insert Image

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: - Prompt for image selection from the camera roll.
- Save selection as as a jpeg.
- The image is saved in a sub folder relative to current folder. (Default is 'imgs', you may change it)
- Preserve the original image orientation.
- Insert a markdown image reference.

**Credits**
I forked and modified the plugins from the following two workflows which either didn't have the relative folder feature or did not working for me(infinite running).

[Insert Photo...](http://www.editorial-workflows.com/workflow/5848481730134016/Qi3BQOLzpGY#)

[insert_image](http://www.editorial-workflows.com/workflow/5793629092184064/Jb-MjQh1u6c)

https://github.com/winddweb

Shared by: Yifeng-winddweb

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
Run Python Script ?
Source Code
#coding: utf-8

from PIL import Image, ExifTags
import photos
import workflow
import console
import editor
import os
import io
import time
from time import gmtime, strftime

FOLDER = 'imgs'
# timestr = time.strftime("%Y-%m-%d")
timestr=strftime("%Y-%m-%dT%H%M%S", gmtime())

img = photos.pick_image()
if not img:
	workflow.stop()

try:
	for orientation, value in ExifTags.TAGS.items():
		if value == 'Orientation':
			break
	exif = dict(img._getexif().items())
	rot_degrees = {3: 180, 6: 270, 8: 90}.get(exif[orientation], 0)
	if rot_degrees:
		img = img.rotate(rot_degrees, expand=True)
# cases: image don't have getexif
except (AttributeError, KeyError, IndexError):
	pass

doc_path = editor.get_path()
doc_dir, fn = os.path.split(doc_path)
default_name = 'figure_{}'.format(timestr)

root, rel_doc_path = editor.to_relative_path(editor.get_path())

filename = default_name + '.jpg'

if img:
	pass
	# console.alert(default_name, filename)
	# filename = console.input_alert('test title', 'test message', filename, 'Button')

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(rel_doc_dir, FOLDER, filename)
editor.set_file_contents(dest_path, img_data.getvalue(), root)

md_path = os.path.join(rel_doc_dir, FOLDER, filename)

workflow.set_output(md_path)
Replace Selected Text ?
Replacement Text
![Image](Input)