Python script to compose iPhone marketing images
An excuse to use Python
I consider myself a polyglot programmer and try to learn a new language every now and again. My latest is Python and I can say that I love it! It’s easy to learn, has a HUGE library, very good support for lists and dictionaries and is flexible enough to be an ideal choice from small scripts to large frameworks.
I’ve been doing a lot of Python scripts for all sorts of small jobs and my latest script might be of interest to some of the readers of this blog.
I was creating a press kit for my latest app and I wanted to get some screenshots of the app and compose them inside an iPhone image.
So, I wanted to get the image on the left and create the one on the right:
Of course I could use PhotoShop or Pixelmator and do this all manually but I had 8 of these and a craving for Python. So I fired up CodeRunner and started writing a Python script. Turns out that, with the use of the incredible Python Imaging Library it was a breeze.
So I decided to open source this so everyone could use it: https://github.com/gpambrozio/PythonScripts. Feel free to grab it, fork it, improve it and make a pull request.
This script uses PIL. The easiest way to install PIL is using pip:
sudo pip install PIL
Using the script
To use the script place your screenshot files in the same folder as the script and the EmptyiPhone.png file and run it. The script will create new files with ss_ prefixes for all .png files found in the folder.
Changing the iPhone image
To use a different image or to adapt the script for an iPad screen for example, change the EmptyiPhone.png image or the name of the image in the script and change the coordinates used to paste the original screen shots. I plan to automate this step by analyzing the image and finding the transparent rectangle in the middle but so far this is a manual step.
Hope you like it.
Keep tuned for more technical and non technical posts. You can subscribe by email, RSS or following me on twitter.