Skip to content

Instantly share code, notes, and snippets.

@STAR-ZERO
Last active May 31, 2020 07:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save STAR-ZERO/68f43723902e931ac0ae to your computer and use it in GitHub Desktop.
Save STAR-ZERO/68f43723902e931ac0ae to your computer and use it in GitHub Desktop.
Androidのxxxhdpiの画像から各解像度にリサイズするPhotoshopスクリプト

概要

Androidのxxxhdpiの画像からxxhdpixhdpihdpimdpiにリサイズしてファイルを書き出すPhotoshopのスクリプト

インストール

/Applications/Adobe Photoshop CC/Presets/ScriptsAndroid resize drawable.jsxをコピーする

コピー後にPhotoshop再起動する

使い方

  1. Photoshopのメニューのファイル -> スクリプト -> Android resize drawableを選ぶ。

  2. xxxhdpiの画像を選ぶ。

  3. 書き出すフォルダを選ぶ。

  4. リサイズされた画像がつくられる

注意

結構テキトーなんで、自己責任でお願いします

try {
var xxhdpiImage = File.openDialog("Select xxxhdpi file.", "*.png", false);
if (xxhdpiImage == null) {
throw "";
}
var doc = open(xxhdpiImage, OpenDocumentType.PNG);
if (doc == null) {
throw "Something is wrong with the file. Make sure it's a valid PNG file.";
}
var startState = doc.activeHistoryState; // save for undo
var initialPrefs = app.preferences.rulerUnits; // will restore at end
app.preferences.rulerUnits = Units.PIXELS; // use pixels
// Folder selection dialog
var destFolder = Folder.selectDialog("Choose an output folder");
if (destFolder == null) {
throw "";
}
// Save icons in PNG using Save for Web.
var sfw = new ExportOptionsSaveForWeb();
sfw.format = SaveDocumentType.PNG;
sfw.PNG8 = false; // use PNG-24
sfw.transparency = true;
doc.info = null; // delete metadata
var baseWidth = Math.floor(doc.width / 4);
var baseHeight = Math.floor(doc.height / 4);
var filename = doc.name;
var images = [
{"folder": "xxxhdpi", "width": baseWidth * 4, "height": baseHeight * 4},
{"folder": "xxhdpi", "width": baseWidth * 3, "height": baseHeight * 3},
{"folder": "xhdpi", "width": baseWidth * 2, "height": baseHeight * 2},
{"folder": "hdpi", "width": Math.floor(baseWidth * 1.5), "height": Math.floor(baseHeight * 1.5)},
{"folder": "mdpi", "width": baseWidth, "height": baseHeight},
];
for (i = 0; i < images.length; i++) {
var image = images[i];
doc.resizeImage(image.width, image.height, null, ResampleMethod.BICUBICSHARPER);
var folder = new Folder(destFolder + "/" + image.folder);
if (!folder.exists) {
folder.create();
}
doc.exportDocument(new File(destFolder + "/" + image.folder + "/" + filename), ExportType.SAVEFORWEB, sfw);
doc.activeHistoryState = startState; // undo resize
}
alert("drawable created!");
} catch (exception) {
// Show degbug message and then quit
if ((exception != null) && (exception != "")) {
alert(exception);
}
} finally {
if (doc != null) {
doc.close(SaveOptions.DONOTSAVECHANGES);
}
app.preferences.rulerUnits = initialPrefs; // restore prefs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment