A command-line utility for generating Android drawables in the required densities.
Project description
The Android asset resizer can be used to generate drawable assets from a larger source image, like an iOS @2x asset or an xhdpi drawable.
The script will generate the expected mdpi, hdpi, xhdpi and xxhdpi assets from the source image.
If you like this library and it’s saved you some time, please consider supporting further development with a Gittip donation!
Requirements
PIL (tested with version 1.1.7, may work with earlier versions)
Installing
$ pip install android-asset-resizer
If you’d like to use the pillow imaging library instead of PIL you can install the script with this command:
$ pip install --no-deps android-asset-resizer && pip install pillow
Examples
You can easily generate Android assets from your @2x iOS assets:
$ aaresize assets/icon@2x.png
Running this command will generate the following assets:
- res - drawable-mdpi - icon.png - drawable-hdpi - icon.png - drawable-xhdpi - icon.png - drawable-xxhdpi - icon.png
These assets were created from the original @2x asset where the icon in the drawable-xhdpi folder is just a copy of the original.
You can also resize an entire directory of images:
$ aaresize assets/*@2x.png
An Android xhdpi asset is roughly equivalent to an @2x asset, so you can easily resize those too:
$ aaresize res/drawable-xhdpi/*.png
If you have a large drawable-xxhdpi asset you can use the --density flag to generate the smaller assets:
$ aaresize res/drawable-xxhdpi/*.png --density=xxhdpi
You can also easily add a prefix to your new assets:
$ aaresize assets/*@2x.png --prefix=ic_
Use the --ldpi flag to generate low density assets:
$ aaresize res/drawable-xhdpi/*.png --ldpi
Use the --exclude flag to specify a list of files that should not be resized:
$ aaresize res/drawable-xhdpi/*.png --exclude=ic_launcher.png,ic_status.png
You can also import the AssetResizer class and incorporate it into your own scripts:
from PIL import Image from android_asset_resizer.resizer import AssetResizer # Create our resizer resizer = AssetResizer(out_dir, source_density='xhdpi', prefix='ic_', image_filter=Image.ANTIALIAS) # Make our resource directories resizer.mkres() # Resize an image resizer.resize(path)
Bug reports
If you encounter any issues, please open a new issue on the project’s GitHub page.
License
See the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for android-asset-resizer-1.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f7e84b04b2d375cc3378d25f945767c248f0cd9f51870801a55103202ede5d8 |
|
MD5 | d28ab9382a9fdc5ce05bda39f93604e1 |
|
BLAKE2b-256 | 9a78439d97397cb2ef0111af641e813adfcba65a79643e6c0ca39a650a394e53 |
Hashes for android_asset_resizer-1.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16f2e2b48d517f46e78374b29cd4320d0ee5d1cf4e779e9176f1c09ecaf20243 |
|
MD5 | d7086ec07e73d83363c59814897a77c4 |
|
BLAKE2b-256 | 000bdfdb5ad159e7fd7fa6d249c8002bfa5fe5aa1aa7a6e3e0214cb6bef1e3fa |