Giter VIP home page Giter VIP logo

android-asset-resizer's Introduction

android-asset-resizer

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/[email protected]

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.

android-asset-resizer's People

Contributors

twaddington avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.