One of the pains for Android development for me is creating drawables in different sizes for various devices. In the past I’d only have a few images at a time to resize so I’d normally just upload them to Android Asset Studio and have the site generate the correct sizes for me.
There are two problems with this approach. First, I have to upload the files one at a time. If I have more than 4 files then it becomes a bit of a chore. Second, I can’t specify what size I want the output. It always generates files that are
Instead of manually editing the images I had (I had a lot) I decided to finally just write an app to handle this for me. You can find it on GitHub at AndroidIconsResizer. Right now it is a little barebones but it quickly and easily handles batches of images.
All options are optional so the simples use is to just run it. If nothing is specified it assumes the current directory for all input or output. By default the output images are all squares and are 100×100 at the mdpi size.
It looks for all the .png files in current directory, resizes them and copies them to the appropriate output directories. If you ran the above command in the following directory
. .. file.png anotherFile.png
then the directory would look like this after
. .. file.png res/ drawable-mdpi/ file.png (100 x 100 pixels) anotherFile.png (100 x 100 pixels) drawable-hdpi/ file.png (150 x 150 pixels) anotherFile.png (150 x 150 pixels) drawable-xhdpi/ file.png (200 x 200 pixels) anotherFile.png (200 x 200 pixels) drawable-xxhdpi/ file.png (300 x 300 pixels) anotherFile.png (300 x 300 pixels)
It is possible to specify different sizes (heights and widths) for the output images. All you need to specify is the size you want the mdpi image. The other sizes are extrapolated based on Google’s iconography recommendations.
> AndroidIconResizer –w 20 –h 50
You can specify the input and output directories just as easily
> AndroidIconResizer –i inputDir –o outputDir
By default the xxxhdpi image isn’t generated since it’s only needed for launcher icons. You can choose to include it with an option
> AndroidIconResizer –-include-xxxhdpi
Or you can just ask the tool itself for some help:
> AndroidIconResizer –help
Those were all the features I needed today, but I’ll probably be expanding on this app in the future. Let me know if you’d want any other features.