分享Photoshop脚本代码_压缩,图片置灰,切图导出等

压缩工具脚本

现在2019,2020cc的photoshop,动则几百mb体积的.psd文件

找到一个工具,可压缩(某些文件压缩不明显),可方便云文档共享:

/**
 * @author Jason
 * @email jiangran@126.com
 * @name PsDeepCleaner
 * @description photoshop metadata deep clean script
 */

function deleteDocumentAncestorsMetadata() {
    if(String(app.name).search("Photoshop") > 0) {

        if(!documents.length) {
            alert("There are no open documents. Please open a file to run this script.")
            return;
        }

        if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

        var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
        xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
        app.activeDocument.xmpMetadata.rawData = xmp.serialize();

        clearDocumentAncestorsForAllLayers(app.activeDocument);

        if (app.activeDocument !== mainDocument) {
            app.activeDocument.close(SaveOptions.SAVECHANGES);
        }else{
            app.activeDocument.save();
        }
    }
}

function clearDocumentAncestorsForAllLayers(doc) {
    try {

        if (doc == undefined) {
            return;
        }

        for (var i = 0; i < doc.layers.length; i++) {
            var curLayer = doc.layers[i];
            if (curLayer.typename != "ArtLayer") {
                clearDocumentAncestorsForAllLayers(curLayer);
                continue;
            }

            if (curLayer.kind == "LayerKind.SMARTOBJECT") {

                app.activeDocument.activeLayer = curLayer;
                
                var idplacedLayerEditContents = stringIDToTypeID("placedLayerEditContents");
                var actionDescriptor = new ActionDescriptor();
                executeAction(idplacedLayerEditContents, actionDescriptor, DialogModes.NO);

                if(app.activeDocument.activeLayer == curLayer){
                    continue;
                }
                deleteDocumentAncestorsMetadata()
                layerSetStr += ("\n"+curLayer.name)

            }
        }
    } catch (e) {
        alert("Layer clean fail.name="+doc+";e="+e)
    }
}

var layerSetStr = "";
var mainDocument = app.activeDocument;
function start(){
    deleteDocumentAncestorsMetadata();
    alert("Clean finished.\n[doc name]:"+mainDocument.name+"\n[layer set]:"+layerSetStr);
}

try{
    if(confirm("Start to clean?")){
        start();
    }
} catch (e) {
    alert("Clean fail.e="+e)
}

 

其他工具下载:

Jscode1.1版本

就算不做游戏,不需要生成UI,也可以切图导出用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

avi9111

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值