--Python uses Ver.2.7.10. --Use pillow of image processing library
--IPhone6 / 6s (4.7) inch images are available. --File names are '01 .png', '02 .png', '03 .png', '04 .png', '05 .png' and put in the same directory as the script. --01 ~ 05.png images are resized for each screen resolution and output to the same directory
sudo easy_install pillow
resize.py
# -*- encoding: utf-8 -*-
from PIL import Image
#File before resizing(4.Assuming a 7-inch size image)
fileNames = ['01.png','02.png','03.png','04.png','05.png']
#Information on each screen resolution
resolutions = [[5.5,1242,2208], [4.7,750,1334], [4.0,640,1136], [3.5,640,960]]
for i in range(5):
for j in range(4):
if j == 0:
# 5.For 5 inches, use resize to enlarge
image = Image.open(fileNames[i], 'r')
resize_image = image.resize((resolutions[j][1], resolutions[j][2]))
resize_image.save('screenshot_' + str(resolutions[j][0]) + '_0' + str(i+1) +'.jpg', 'JPEG', quality=100, optimize=True)
else:
# 4.7 inches or less is less deteriorated when using thumbnail
image = Image.open(fileNames[i], 'r')
canvas = Image.new('RGB', (resolutions[j][1], resolutions[j][2]), (255, 255, 255))
image.thumbnail((resolutions[j][1], resolutions[j][2]), Image.ANTIALIAS)
x = (resolutions[j][1] - image.size[0])/2
canvas.paste(image, ( x, 0))
canvas.save('screenshot_' + str(resolutions[j][0]) + '_0' + str(i+1) +'.jpg', 'JPEG', quality=100, optimize=True)
python resize.py
Recommended Posts