Automatically resize screenshots for the App Store for each screen in Python

Premise

--Python uses Ver.2.7.10. --Use pillow of image processing library

How to use

--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

Pillow installation

sudo easy_install pillow

Python script

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)

Run

python resize.py

Recommended Posts

Automatically resize screenshots for the App Store for each screen in Python
Check the operation of Python for .NET in each environment
MongoDB for the first time in Python
Switch the module to be loaded for each execution environment in Python
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
Match the distribution of each group in Python
Tips for hitting the ATND API in Python
Use the LibreOffice app in Python (3) Add library
[Python] I created an app that automatically downloads the audio file of each word used for the English study app.
Store the stock price scraped by Python in the DB
Output the specified table of Oracle database in Python to Excel for each file
Using the LibreOffice app in Python (1) Where are the macros?
Whole type conversion for each dataframe column in python
Check the processing time and the number of calls for each process in python (cProfile)
A program that automatically resizes the iOS app icon to the required image size in Python
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
How to find the cumulative sum / sum for each group using DataFrame in Spark [Python version]
[Understand in the shortest time] Python basics for data analysis
Automatically get the port where Arduino is stuck in Python
Get the number of occurrences for each element in the list
Google search for the last line of the file in Python
Get the index of each element of the confusion matrix in Python
Download the file in Python
Find the difference in Python
Use parameter store in Python
Search for strings in Python
Techniques for sorting in Python
Qt for Python app self-update
About "for _ in range ():" in python
Get the Ticker Symbol for US exchange listed stocks in Python
How to set the output resolution for each keyframe in Blender
Learning history for participating in team app development in Python ~ Django Tutorial 5 ~
Wrap (part of) the AtCoder Library in Cython for use in Python
Learning history for participating in team app development in Python ~ Django Tutorial 4 ~
Learning history for participating in team app development in Python ~ Django Tutorial 1, 2, 3 ~
[Introduction to Python] How to use the in operator in a for statement?
Learning history for participating in team app development in Python ~ Django Tutorial 6 ~
Dockerfile with the necessary libraries for natural language processing in python
Learning history for participating in team app development in Python ~ Django Tutorial 7 ~
Review the basics in 1 minute! Python Priority queue for fast minimums
python note: map -do the same for each element of the list
Try using FireBase Cloud Firestore in Python for the time being
Check for memory leaks in Python
Getting the arXiv API in Python
Check for external commands in python
Python in the browser: Brython's recommendation
Hit the Sesami API in Python
Get the desktop path in Python
Automatically format Python code in Vim
Put the module in the Pepper app
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Detect app releases on the App Store
Hit the web API in Python
See python for the first time
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the desktop path in Python
What is the python underscore (_) for?