4

给psd瘦身

 2 years ago
source link: https://wocai.de/post/2019/07/%E7%BB%99psd%E7%98%A6%E8%BA%AB/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

设计师交付设计稿的时候经常会遇见一个问题,怎么这个psd这么大?

上周设计师给我做了一个icon,只有128*128像素大,按理说是一个很小的文件。

结果这个 psd 文件竟然有 160 mb大,太可怕了。

经过搜索之后发现一个脚本,原来记载在 github issue 中。

脚本#

为了我自己后面使用方便,这里直接贴一下脚本:

function deleteDocumentAncestorsMetadata() {
  whatApp = String(app.name); //String version of the app name
  if (whatApp.search("Photoshop") > 0) {
    //Check for photoshop specifically, or this will cause errors
    //Function Scrubs Document Ancestors from Files
    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);
    // Begone foul Document Ancestors!
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
  }
}
//Now run the function to remove the document ancestors
deleteDocumentAncestorsMetadata();

简单的看,这段脚本的核心原理在于这几句:

var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
// Begone foul Document Ancestors!
xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
app.activeDocument.xmpMetadata.rawData = xmp.serialize();

应该是将psd文件中的 rawData.DocumentAncestors 直接删掉了。

按照 Metadata Bloat – photoshop:DocumentAncestors Clearing all metadata (in all smart object levels)

这个字段是用来存储图层的复制粘贴记录的,如果历史操作很多,元信息就会非常非常大……

使用#

首先将上面的脚本复制到文件中,保存为 lightenPSD.jsx ,文件名无所谓,后缀是 jsx。

打开要瘦身的psd文件,点击 文件 - 脚本 - 浏览,然后打开刚才这个jsx文件就行。

运行后我发现这个psd只有54kb大了……而且图层和之前的一模一样。

如果还是不行#

刚才的这个案例只针对于历史操作很多的文档,如果不行,还有以下几种方法供参考:

  1. 降低文档的分辨率
  2. 降低文档的尺寸
  3. 删除无用的图层
  4. 对于不太会修改的情况,合并一些图层

如果以上对于减少psd文件还是没用,建议用 ai/sketch 矢量图工具重画一下设计稿,可能效果会更好。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK