Last active
April 17, 2021 04:44
-
-
Save karino2/bc670a09c9872769eab952d618936266 to your computer and use it in GitHub Desktop.
Resize android icon, invoke based. Use Pillow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from invoke import task | |
# pip install Pillow | |
from PIL import Image | |
import os | |
@task(help={"src": "元のサイズのpngファイル", | |
"dest": "置く先のディレクトリ", | |
"size": "解像度。192, 144, 96, 72, 48のどれか"}) | |
def resize_and_move(c, src, dest, size): | |
""" | |
srcのファイルをリサイズしてdest以下に置く。 | |
""" | |
img = Image.open(src) | |
sz = int(size) | |
resized = img.resize((sz, sz), Image.ANTIALIAS) | |
resized.save(os.path.join(dest, os.path.basename(src))) | |
@task(help={"src": "元のサイズのpngファイル", | |
"destdir": "AndroidManifest.xmlの置いてあるディレクトリ(resの上)"}) | |
def all(c, src, destdir): | |
""" | |
srcで指定されたpngを、192, 144, 96, 72, 48にリサイズしてdestdirのそれぞれの場所に置く。 | |
usage: invoke all ./ic_launcher_round.png ../TextDeck/app/src/main | |
""" | |
reses = [(192, "mipmap-xxxhdpi"), (144, "mipmap-xxhdpi"), (96, "mipmap-xhdpi"), (72, "mipmap-hdpi"), (48, "mipmap-mdpi")] | |
for res, bname in reses: | |
dest = os.path.join(destdir, "res", bname) | |
resize_and_move(c, src, dest, res) | |
@task(help={"basename": "アイコンの名前。outline_refresh_white_24.pngならoutline_refresh", | |
"color": "whiteかblack", | |
"src": "マテリアルデザインのダウンロードしたアイコンのresディレクトリ", | |
"destdir":"コピーするプロジェクトのresフォルダ"}) | |
def copy_actionbar_icons(c, basename, color, src, destdir): | |
""" | |
iconライブラリからダウンロードしたアイコンをコピーする。 | |
https://fonts.google.com/icons | |
usage: invoke copy-actionbar-icons outline_refresh white ./res ../TeFWiki/app/src/main/res | |
""" | |
denses = ["xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi"] | |
c.run(f"cp {src}/drawable/{basename}_24.xml {destdir}/drawable/") | |
c.run(f"cp {src}/drawable/{basename}_24.xml {destdir}/drawable-v24/") | |
for dense in denses: | |
c.run(f"cp {src}/drawable-{dense}/{basename}_{color}_24.png {destdir}/mipmap-{dense}/{basename}_24.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment