【问题标题】:PNG export with specific file size using ExtendScript for Adobe Illustrator使用 ExtendScript for Adob​​e Illustrator 以特定文件大小导出 PNG
【发布时间】:2021-04-09 12:18:54
【问题描述】:

我正在尝试在 Extendscript 中创建一个脚本来绘制一些东西,然后将整个画板导出为 4500x5400 像素(或任何其他特定大小)的 PNG。 这是我现在的代码:

//create new document with my desired size     
var myDoc = app.documents.add();
myDoc.width = 4500;
myDoc.height = 5400;
    
//create a rectangle that is smaller than the artboard
var rect = myDoc.layers[0].pathItems.rectangle(700,300,72,100);

//export Image with name newImage.png (I have a specific path here) 
exportFileToPNG24 ("~/newImage.png");
    

function exportFileToPNG24(dest) {
  if (app.documents.length > 0) {
    var exportOptions = new ExportOptionsPNG24();
    exportOptions.artBoardClipping = true; //this option makes sure I export 
                                          //the whole artboard and not just 
                                          //the rectangle    
    var type = ExportType.PNG24;
    var fileSpec = new File(dest);
    
    app.activeDocument.exportFile(fileSpec, type, exportOptions);       
  }
}

脚本确实将整个画板导出为 png。但 PNG 的大小始终为 612x792 像素。如何让它以 4500x5400 像素导出?

【问题讨论】:

    标签: export png adobe-illustrator extendscript


    【解决方案1】:

    而不是这个:

    var myDoc = app.documents.add();
    myDoc.width = 4500;
    myDoc.height = 5400;
    

    以这种方式创建新文档是有意义的:

    var preset    = app.getPresetSettings("Web");
    preset.units  = RulerUnits.Pixels;
    preset.width  = 4500;
    preset.height = 5400;
    var myDoc     = app.documents.addDocument("Web", preset);
    

    或者您可以创建一个具有默认大小的新文档,然后以这种方式进行更改:

    var myDoc = app.documents.add();
    myDoc.artboards[0].artboardRect = [0,5400,4500,0];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 2012-06-23
      • 2013-05-18
      相关资源
      最近更新 更多