Another script for generating icons for Android

Hello, Habr!

Small introduction


For a long time I have been working as a tester of mobile applications. Mostly android applications (although there were both WinCE and iOS). Mostly hands (although I tried and automate with monkeyrunner and uiautomator). Recently, more and more time has to be devoted to interface design, management issues, releases, and other matters. In a word, puzzles have to be solved, although usually simple, but quite diverse. I would like to talk about one of them.

What, in fact, is the matter


Recently, a colleague in the Rumsunrise team and I experimented with support for android 5 and material design in our applications. In the process of preparing the project, we encountered an unexpected minor problem from the field of design.

The fact is that we renamed some icons from the standard icon pack so that it is more convenient to use them in our projects. And with the release of the new Android and, accordingly, the new icon pack from Google, we needed to add new icons to the project.

What did this mean for us? Pick up new icons from material-design-icons for each dpi value and sort them into the necessary directories. Next, rename the icons in each directory in accordance with the custom design. When there are two or five icons, there are no problems - with your hands this is done quickly and painlessly. But if there are 25 icons, for example, then renaming even part of them manually is long and uninteresting. And if you consider that in addition to the icons, there is another graphic (which, by the way, may change from time to time), then the situation was completely sad.

And then we thought that it would be nice to do this work once for icons and graphics that have the highest resolution (now this is xxxhdpi), and do the rest of the work with a script.

What is Google? A quick study of the issue led us to a number of scripts for Gimp and Photoshop and to tools like the icon generator from the Android Asset Studio suite . Honestly, this did not suit us very much. At least, because it was necessary to do a lot at once. In order not to resize, rename and not lay out all the icons and graphics manually, we wrote a simple (you can even say, primitive) python script, which now does it for us.

So, I have a set of xxxhdpi graphics, ready to use in an android project. From it I need to get icons of all the required sizes and put them in the appropriate directories.

All I need to do now is:

Put the ready-made needed xxxhdpi-icons in some directory and do:

$ iconic2.py /path/to/xxxhdpi/icons

What exactly does the script do:

  • creates drawable- * dpi subdirectory in the specified directory;
  • takes xxxhdpi images;
  • reduces them to the necessary sizes;
  • lays out the appropriate directories;
After that, it remains only to pick up the finished sets and put them in the project.

To resize the icons, we use PIL or Pillow (for ubuntu x64). So what you should do first:
$ sudo apt install pillow

Or what you usually do to install packages in your distribution.

The script itself is available in the mercurial repository on Bitbucket . I want to say that the script does not pretend to be a universal tool or a sample of good code. We know that there are many more places that can be done better. But now it works and saves us time. I hope he saves him and you.

Also popular now: