cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              // PSD ファイル名(拡張子は、.psd で決めうち)
var strResourceNames = ['splash_720', 'splash_480', 'splash_360', 'splash_270', 'splash_180', 'splash_120'];

// Android 側、解像度名
var strSizeNames = ['xxxhdpi', 'xxhdpi', 'xhdpi', 'hdpi', 'mdpi', 'ldpi'];

var doc = app.activeDocument;
var strPath = doc.path;

var height;
var width;

function main() {
    
    preferences.rulerUnits = Units.PIXELS;    

    for (var index = 0; index < strResourceNames.length; index++) {
        
        resizeCanvas();
        
        addPatch();
        
        saveFile(index);

        if (! changeFile(index + 1)) break;
    }
}
main();


/*
 * カンバスサイズを元画像の +2 にリサイズするメソッド
 */
function resizeCanvas() {
    
    height = doc.height.value;
    width = doc.width.value,

    doc.resizeCanvas(width + 2, height + 2);
}

/*
 * パッチを当てるメソッド
 */
function addPatch() {
    
    var contentInfo = []; // x, y, width, height。(x, y):選択領域左上座標。width, height 選択領域幅と高さ
    for(var index = 0; index < 6; index++) {
        
        switch(index) {
            
            case 0:
                contentInfo = [0, 1, 1, 1];
                break;
            case 1:
                contentInfo = [1, 0, 1, 1];
                break;
            case 2:
                contentInfo = [width, 0, 1, 1];
                break;
            case 3:
                contentInfo = [0, height, 1, 1];
                break;
            case 4:
                contentInfo = [width + 1, 2, 1, height - 2];
                break;
            case 5:
                contentInfo = [2, height + 1, width - 2, 1];
                break;
        }
    
        selectArea(contentInfo);
        fillColor();
    }
}
/*
 * 指定領域を選択するメソッド
 */
function selectArea(contentInfo) {
    
    var rectangle = [
        [contentInfo[0], contentInfo[1]],
        [contentInfo[0] + contentInfo[2], contentInfo[1]],
        [contentInfo[0] + contentInfo[2], contentInfo[1] + contentInfo[3]],
        [contentInfo[0], contentInfo[1] + contentInfo[3]]
                                ];
    doc.selection.select(rectangle);
}
/*
 * 選択領域を塗りつぶすメソッド
 */
function fillColor() {
    
    var color = new SolidColor();
    color.rgb.hexValue = '000000';
    doc.selection.fill(color, ColorBlendMode.NORMAL, 100, false);
}

/*
 * 9Patch ファイルを保存するメソッド
 */
function saveFile(index) {
    
    var file9Patch = new File(doc.path + '/splash_' + strSizeNames[index] + '.9.png');
    var pngOpt = new PNGSaveOptions();
    pngOpt.interlaced = false;
    
    doc.saveAs(file9Patch, pngOpt, true, Extension.LOWERCASE);
}

/*
 * 元画像を切り替えるメソッド
 */
function changeFile(indexNext) {
    
    doc.close(SaveOptions.DONOTSAVECHANGES);
    if (indexNext != strResourceNames.length) {
        
        var fileResource = new File(strPath + '/' + strResourceNames[indexNext] + '.psd');
        try {
            doc = app.open(fileResource);
            return true;
        }
        catch(e) {
            alert(strResourceNames[indexNext] + ".psd は存在しません。\n\nファイルを準備して、処理を最初からやり直してください");
            return false;
        }
    }
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console