一个命令行实用程序,用于在所需密度下生成android可绘制文件。
android-asset-resizer的Python项目详细描述
android资产调整器可用于从更大的 源映像,例如ios@2xasset或xhdpidrawable。
脚本将生成预期的mdpi、hdpi、xhdpi和 xxhdpi来自源映像的资产。
如果你喜欢这个图书馆,而且它节省了你一些时间,请考虑 以Gittip donation支持进一步的开发!
要求
安装
$ pip install android-asset-resizer
如果您想使用枕头图像库而不是PIL,可以安装 使用此命令的脚本:
$ pip install --no-deps android-asset-resizer && pip install pillow
示例
您可以轻松地从@2xios资产生成android资产:
$ aaresize assets/icon@2x.png
运行此命令将生成以下资源:
- res - drawable-mdpi - icon.png - drawable-hdpi - icon.png - drawable-xhdpi - icon.png - drawable-xxhdpi - icon.png
这些资产是从原始的@2xasset创建的,其中 drawable-xhdpi文件夹只是原始文件夹的副本。
您还可以调整整个图像目录的大小:
$ aaresize assets/*@2x.png
android xhdpi资产大致相当于@2x资产,因此 也可以轻松调整大小:
$ aaresize res/drawable-xhdpi/*.png
如果您有一个大的drawable-xxhdpi资产,那么可以使用--density 生成较小资产的标志:
$ aaresize res/drawable-xxhdpi/*.png --density=xxhdpi
您还可以轻松地为新资产添加前缀:
$ aaresize assets/*@2x.png --prefix=ic_
使用--ldpi标志生成低密度资产:
$ aaresize res/drawable-xhdpi/*.png --ldpi
使用--exclude标志指定不应 调整大小:
$ aaresize res/drawable-xhdpi/*.png --exclude=ic_launcher.png,ic_status.png
您还可以导入AssetResizer类并将其合并到 自己的脚本:
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)
错误报告
如果您遇到任何问题,请在项目的 GitHub page。
许可证
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.