When creating assets for mobile apps, it can be a pain – and a time drain – to manually resize multiple images to their relevant screen density. For example: 1x, 2x, 3x in iOS or MDPI, HDPI, XHDPI etc in Android.
With a little experimentation, I created an AppleScript that allows you to re-size and copy an image into various asset-specific subfolders. And with Automator magic, this can make your resizing process as simple as right-clicking on a file.
5 Steps to Heaven
- Copy the contents of this AppleScript file to the Clipboard.
- Open the Automator app in Mac OS, then create a new workflow of type ‘Service’.
- Set the input to your Service with ‘files or folders’ and ‘Finder’ in the dropdowns.
- Drag the ‘Run Applescript’ action into your workflow and then paste the contents of the AppleScript file into it.
- Save the Service using a descriptive name such as ‘Create Mobile Assets in Folders’.
Using the AppleScript file
- Save your image file somewhere at x4 of full size, i.e. XXXHDPI.
- Right click on the image file in ‘Finder’ and choose the shiny new option that should now be in the drop-down menu.
- Subfolders will be created for each size ratio and the image will be copied into them.
As mentioned above, the script assumes that your image is already x4 of display size, i.e. XXXHDPI in Android terminology. If you need to change this, or customise the sizes and ratios, just edit the first two lines of the script accordingly.
I hope you find the workflow useful as it can save many hours of fiddling around!