Skip to main content

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

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

Copyright 2013 Tristan Waddington

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Metadata

Release files for android-asset-resizer 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for android-asset-resizer 1.3.1
File Size Uploaded Provenance Actions
android-asset-resizer-1.3.1.tar.gz 10.1 kB Without provenance Details for android-asset-resizer-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for android-asset-resizer 1.3.1
File Interpreter ABI Platform Actions
android_asset_resizer-1.3.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for android_asset_resizer-1.3.1-py2.py3-none-any.whl

Total release size: 19.4 kB

Release files / android-asset-resizer-1.3.1.tar.gz

Download URL android-asset-resizer-1.3.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1c9dc79e532d672febc39d94bc8bef884cc0ea23dfe0f6a9b49de617e515f91d
BLAKE2b-256 checksum
How to use checksums
979238b06c7dd7d2bc1cf4cbd57c145c34c3a249cdd2596f7477e8db6eb83420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / android_asset_resizer-1.3.1-py2.py3-none-any.whl

Download URL android_asset_resizer-1.3.1-py2.py3-none-any.whl
Size 9.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ab31d1c71d7ebfcb001736371b7fc58b77d1734530a1d7332ede5fa86b2eec73
BLAKE2b-256 checksum
How to use checksums
33eeb898e56f308a954919d7b36f748f5ce176c99e94169d110742e480e46440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for android-asset-resizer 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page