📜 ⬆️ ⬇️

PNG resize automation for iOS and Android applications

I have been developing mobile applications for Android and iOS for several years. Previous projects contained quite a few graphics, within 10 elements, but recently I took up a large project containing several dozen different images - icons, backgrounds, etc.

As all mobile developers know, all these resources need to be saved for different DPI screen sizes for the best display quality. Recently, a variety of DPIs have divorced a whole zoo - under Android there are 5 main ones (mdpi, hdpi, x / xx / xxxhdpi), and under iOS already at least 3 (@ 1x, @ 2x, @ 3x, besides, some resources need to be optimized for ~ ipad separately).

If earlier I coped with this in general graphic editors such as Paint.NET or Photoshop, then now it has taken too long to fit the dimensions. In this regard, it was decided once and for all to get rid of this routine.

A small Python console script was originally written (<1kb source code), which took the path to png as input, requested dimensions and saved copies of the image into separate subfolders. It was very uncomfortable and I began to improve it.
')
The final version of the solution to the immediate problem has become much more convenient:



It’s easy to use:
  1. Open the original image in high resolution (the path to the picture is remembered by the program, because often all the resources are in the same folder);
  2. Select the initial size (for drawable-mdpi or @ 1x for Android and iOS, respectively);
  3. If only height or width is entered, then the second dimension can be adjusted by pressing one button. Conveniently, if it is known that the interface element must have a certain height, but adjust the width automatically;
  4. In the version for iOS (screenshot below) it is possible to select the checkbox "~ ipad", which will add the corresponding suffix;
  5. By pressing the “DO IT!” Button, the pictures are scaled and saved.

For Android, pngs are saved in separate drawable- * dpi folders, and for iOS, in the result-images folder with the corresponding suffix @ * x (~ ipad).

The iOS version is not much different in interface (screenshot from Windows, because it was at hand):



The script is written in Python, for the GUI uses TkInter, for the resize of images - Pillow (fork of the Python Imaging Library).
The script size is only 6 kb. Tested on Windows and Mac.

Sources:
Android Drawable Downsampler: pastebin.com/1sJPnuUs
iOS ImageAsset Downsampler: pastebin.com/8sdyPaqZ
I didn’t upload on GitHub, because it was just too lazy to create a separate repository for such a small script.

Build for Windows:
Android Drawable Downsampler: Download
Build for OS X:
Android Drawable Downsampler: Download
iOS ImageAsset Downsampler: Download

Hope this tiny utility will be useful.

Thanks for attention!

Source: https://habr.com/ru/post/254177/


All Articles