Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // 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

Console