1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Androidの画像ファイルをdp解像度毎にディレクトリに分ける処理

Posted at

はじめに

svgで作れば、こんなものは必要ありません。
お勉強です。

sketchで書き出すとき

6f688d72-245f-55c5-71f5-abac9878a7b1.png

こんな感じでexportすると、まだディレクトリに振り分けられていない。
大量に書き出したときに、コンソール叩いて一気に振り分ける方法が以下。

書き出し方法

作る場所はどこでも良いです。

解像度毎のディレクトリを作成

cd Desktop/res/
mkdir drawable-xxxhdpi; drawable-xxhdpi; mkdir drawable-xhdpi; mkdir drawable-hdpi; mkdir drawable-mdpi

書き出す。

for file in $(find . -type f -iname '*@4x*'); do
  mv "$file" "drawable-xxxhdpi/${file/@4x/}"
done
for file in $(find . -type f -iname '*@3x*'); do
  mv "$file" "drawable-xxhdpi/${file/@3x/}"
done
for file in $(find . -type f -iname '*@2x*'); do
  mv "$file" "drawable-xhdpi/${file/@2x/}"
done
for file in $(find . -type f -iname '*@1.5x*'); do
  mv "$file" "drawable-hdpi/${file/@1.5x/}"
done
for file in $(find ./ -type f -maxdepth 1 -iname '*.png' | grep -v "@"); do
  mv "$file" "drawable-mdpi/${file}"
done

これで、それぞれのディレクトリに画像が振り分けられたはず。
おわり。

良さげなプラグインがあった・・・

https://github.com/nickstamas/Sketch-Better-Android-Export
https://github.com/GeertWille/sketch-export-assets

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?