如何解决使用 ExtendScript for Adobe Illustrator 以特定文件大小导出 PNG
我正在尝试在 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 像素导出?
解决方法
取而代之的是:
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];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。