Indesign CS6 脚本 - 导出图像
Indesign CS6 Scripting - Exporting images
我在 indesign cs6 中编写 js 脚本以导出格式化图像时遇到问题。 下面的代码(在此网站上找到并稍作修改)仅打开文档。
理想情况下,脚本将遍历我文档中的所有格式化/裁剪图像,并将它们导出到桌面上的新文件夹中,但使用原始文件名。
任何帮助将不胜感激:
test();
function test(){
var myDoc = app.open('/Users/StudioA/Desktop/file.indd');
var myGroups = myDoc.groups;
//for each group...
for (var i = 0;i < myGroups.length; i++){
// for each rectangle in the group...
for(var r = 0; r< myGroups[i].rectangles.length; r++){
var myRect = myGroups[i].rectangles[r];
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File('/Users/StudioA/Desktop/Export/' + myRect.name + '.jpg');
myRect.exportFile(ExportFormat.JPG, myFile);
}
}
}
文件名不位于矩形上,而是位于与放置的图形相关的链接上。这应该在给定打开文档的情况下执行您想要的操作:
test();
function test() {
var myDoc = app.activeDocument, apis = myDoc.allPageItems, rect, fileName;
while ( rect = apis.pop() )
{
if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue; }
fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /'.[a-z]{2,4}$/i, '.jpg' );
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File (Folder.desktop+"/"+ fileName);
rect.exportFile(ExportFormat.JPG, myFile);
}
}
只需添加我的详细版本,该版本适用于 InDesign 中的当前选择并提供控制台反馈。它重命名带有前缀"crop_"的图像,并将它们保存到 ~/temp
exportSelectedImages();
function exportSelectedImages() {
// configure export settings
app.jpegExportPreferences.exportResolution = 72;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
// collect selected objects
var selected = app.activeDocument.selection;
$.writeln("Got " + selected.length + " selected objects...");
// process selected objects
for (var i = 0; i < selected.length; i++) {
var cursor = selected[i];
var img = cursor.images;
$.writeln("Processing #" + (i+1) + "/" + selected.length);
$.writeln("'t Type: " + cursor.constructor.name);
// verify if object contains an image or not
if (cursor.images.length > 0) {
var img = cursor.images[0];
$.writeln("'t Contains image of type " + img.imageTypeName);
var imageFileName = cursor.images[0].itemLink.name;
$.writeln("'t File Name: " + imageFileName);
} else {
$.writeln("'t Not an image");
}
// save the object to a jpeg in path specified below
var myFile = new File('~/temp/' + "crop_" + imageFileName + '.jpg');
cursor.exportFile(ExportFormat.JPG, myFile);
}
$.writeln("Done.");
}
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 角度:在ng重复上切换图像
- 画廊图像未显示
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- Javascript排序的图像弹出窗口..可以't单独弹出
- 画布数据到图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使图像在单击时展开到不大于浏览器
- Html页面上的多个Base64图像和平滑加载
- UIAutomation放大图像
- 使用javascript在Flash中加载外部图像
- 可以在这里为背景图像设置滤镜吗
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 使用 js 将背景图像设置为 HTML
- Javascript将图像src更改为淡入淡出
- 无法在本地计算机中将画布另存为图像
- 压缩phonegap中ios的图像插件
- Indesign CS6 脚本 - 导出图像