Reduce photo sizes

Our limited Internet bandwidth required some resourcefulness to share photos. I've been using the amazing coders' app Pythonista on my iPhone. It lets me write Python code to play around, experiment, and sometimes do something useful. In this case I modified some example code to check or reduce the size of my photos. Photos from my fancy camera as well as modern smartphones are high to extremely high resolution. This means that they have lots of detail but are also large files that take a lot of bandwidth to upload. So reducing the file size is helpful for sharing over the Internet.

Here's the code if you'd like to use it:

'''
Use PIL/Pillow to check an image's size or reduce it.
'''

from PIL import Image, ImageOps
from PIL.Image import BILINEAR
import dialogs
import photos

def color_tiles(img):
	size = img.size
	small_img = img.resize((int(size[0]/2), int(size[1]/2)), BILINEAR)
	bw_img = small_img.convert('1', dither=False)
	gray_img = bw_img.convert('L')
	result = Image.new('RGB', size)
	tile1 = ImageOps.colorize(gray_img, 'green', 'red') 
	tile2 = ImageOps.colorize(gray_img, 'purple', 'yellow')
	tile3 = ImageOps.colorize(gray_img, 'yellow', 'brown')
	tile4 = ImageOps.colorize(gray_img, 'red', 'cyan')
	result.paste(tile1, (0, 0))
	result.paste(tile2, (int(size[0]/2), 0))
	result.paste(tile3, (0, int(size[1]/2)))
	result.paste(tile4, (int(size[0]/2), int(size[1]/2)))
	return result

def resize(img):
	size = img.size
	small_img = img.resize((int(size[0]/2), int(size[1]/2)), BILINEAR)
	return small_img

def get_size(img):
	size = img.size
	return '{0} x {1}'.format(size[0], size[1])

def main():
	i = dialogs.alert('Image', '', 'Demo Image', 'Select from Photos')
	if i == 1:
		img = Image.open('test:Lenna')
	else:
		img = photos.pick_image()
	option = dialogs.alert('Select Option', '', 'Resize', 'Show size')
	if option == 1:
		resize(img).show()
		print('Tip: You can tap and hold the image to save it to your photo library.')
	else:
		# normal camera default: 3264x2448
		# face camera default: 1280x960
		size = get_size(img)
		dialogs.alert(size)

if __name__ == '__main__':
	main()