PSD文件过大及导出图片过大该怎么办
诸位有没有遇到明明100px的图片有几百M,
在者一个800-800px的psd文件里面就三个图层竟然有几个G的情况
我遇到过 :@(尴尬) 前几天在网上偶然看到了解决方案顺便就分享下
PSD源文件过大解决方案:
/**
* @author Jason
* @email jiangran@126.com
* @name PsDeepCleaner
* @description photoshop metadata deep clean script
*/
function test(){
alert(app.activeDocument.layers.length);
alert(app.activeDocument.layers[2]);
alert(documents.length);
alert(app.activeDocument.layers[2].kind);
app.activeDocument.activeLayer = app.activeDocument.layers[0];
var idplacedLayerEditContents = stringIDToTypeID("placedLayerEditContents");
var actionDescriptor = new ActionDescriptor();
executeAction(idplacedLayerEditContents, actionDescriptor, DialogModes.NO);
alert(app.activeDocument);
}
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){
// open fail, maybe this layer is AI, ignore.
//alert("open fail,activeLayer="+app.activeDocument.activeLayer+";curLayer:"+curLayer)
continue;
}
deleteDocumentAncestorsMetadata()
layerSetStr += ("\n"+curLayer.name)
// var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
// xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
// app.activeDocument.xmpMetadata.rawData = xmp.serialize();
// deleteDocumentAncestorsMetadataByInnerLayer();
}
}
} catch (e) {
alert("Layer clean fail.name="+doc+";e="+e)
}
}
function deleteDocumentAncestorsMetadataByInnerLayer() {
clearDocumentAncestorsForAllLayers(app.activeDocument);
}
function recurArtLayer(layers){
for(var i=0; i<layers.length; i++){
//alert(layers[i]+"--"+layers[i].kind)
if(layers[i].grouped!=false){
recurArtLayer(layers[i].linkedLayers);
alert(layers[i]+":"+layers[i].linkedLayers)
}else if(layers[i].kind=="LayerKind.SMARTOBJECT"){
alert(layers[i]+"--"+layers[i].kind)
deleteArtLayerAncestorsMetadata(layers[i])
}
}
}
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?")){
// test();
start();
}
} catch (e) {
alert("Task execute fail.e="+e)
}
新建一个文本文档,然后复制上述代码,保存后修改.txt 后缀为.jsx。
也可以直接下载我打包好的文件psCleaner.zip
使用方法:在导出图片前,点击-文件-脚本-浏览,选中刚刚保存的 jsx 文件即可。
导出图片太大解决方案:
/**
* 此解决方案来自[jdeal.cn]
*/
function deleteDocumentAncestorsMetadata() {
whatApp = String(app.name);
if(whatApp.search("Photoshop") > 0) {
if(!documents.length) {
alert("没有打开的文档,请打开一个文件以运行此脚本。")
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();
}
}
deleteDocumentAncestorsMetadata();
新建一个文本文档,然后复制上述代码,保存后修改.txt 后缀为.jsx。
也可以直接下载我打包好的文件imgbig.zip
使用方法:在导出图片前,点击-文件-脚本-浏览,选中刚刚保存的 jsx 文件即可。
下次遇到这样的情况,诸位可以试试。
亲测有效哦~~
B0ae个人成长计划-让,进步发生
----利她,有价值,不打扰----
空空如也!