Skip to content

Instantly share code, notes, and snippets.

@rjp
Created December 24, 2016 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjp/17e2a642db3b2fa6d9c57205dd35b305 to your computer and use it in GitHub Desktop.
Save rjp/17e2a642db3b2fa6d9c57205dd35b305 to your computer and use it in GitHub Desktop.
stripe.py
# coding: utf-8
import appex
import Image
import photos
def main():
global appex
global Image
if not appex.is_running_extension():
print ('Running in Pythonista app, using test image...')
imglist = photos.pick_image(multi=True)
else:
imglist = appex.get_images()
if imglist:
import appex
from PIL import Image, ImageDraw
firstImage = imglist[0]
(w, h) = firstImage.size
images = [firstImage]
for q in imglist[1:]:
print("%d,%d %d,%d" % (w,h,q.size[0],q.size[1]))
if q.size[0] != w or q.size[1] != h:
raise "Must match in dimensions"
images.append(q)
slices = len(images)
sliceWidth = (1.0*w) / slices
leftEdge = 0
rightEdge = -1
chopWidth = -1
outputImage = Image.new("RGB", (w, h))
draw = ImageDraw.Draw(outputImage)
borders = []
for chop in images:
rightEdge = leftEdge + int(sliceWidth + 0.5)
if rightEdge > w:
rightEdge = w
chopWidth = rightEdge - leftEdge + 1
chopped = chop.crop((leftEdge,0,rightEdge,h))
outputImage.paste(chopped, (leftEdge,0))
borders.append(rightEdge)
leftEdge = rightEdge
for border in borders[:-1]:
draw.line((border-2,0, border-2,h), fill="white", width=4)
outputImage.show()
else:
print('No input image found')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment