-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimg_rotate.py
36 lines (28 loc) · 1.14 KB
/
img_rotate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding: utf-8
## Rotate an image (either from external apps' share-sheet, or via photo-roll)
import photos, appex, sys, console, Image
if appex.is_running_extension():
im = appex.get_image()
else:
im = photos.pick_image()
if im is None:
console.hud_alert("No image chosen", "error", 1.0)
sys.exit(0)
else:
assert str(type(im))[8:-2][4:].partition("ImagePlugin")[0] in ("Bmp", "Gif", "Jpeg", "Png", "Ppm", "Tiff")
keep_original = console.alert("Rotate original image?", "Rotate & copy?", \
"Rotate Original", "Rotate Copy", hide_cancel_button=True)
if keep_original == 2:
im2 = im.copy()
else:
im2 = im
degrees = int(console.input_alert("Rotate image __ degrees", "Use multiples of 90"))
assert divmod(abs(degrees), 360)[1] in (0, 90, 180, 270)
deg = (degrees % 360) if not (0 < degrees < 360) else degrees
img = im2.rotate(deg)
saved = photos.save_image(img)
if saved:
console.hud_alert("Successfully saved rotated image")
img.show()
else:
console.hud_alert("Successfully saved rotated image", "error")