123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              // 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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console