在 Illustrator 中导出多种尺寸的图像
Exporting multiple sized images in Illustrator
我想导出不同尺寸的 iOS 应用程序图标,但不必为每个尺寸都做!有没有一种方法可以使用 Adobe Illustrator 一次性导出各种不同大小的 PNG?
我自己找到了答案!
http://www.adobe.com/devnet/illustrator/scripting.html
详见上文link;脚本是指示 Illustrator 执行一个或多个任务的一系列命令。
因此,通过使用以下脚本,我能够根据需要导出多个不同尺寸的图像。
#target Illustrator
/**
* export multiple PNG's in different sizes
* @author Alexandros Harvey
*/
// Adapted to export an Illustrator file in various sizes by Alexandros Harvey
// based on how to export images as CSS Layers by CarlosCanto
if (app.documents.length > 0) {
main();
}
else alert('Cancelled by user');
function main() {
var document = app.activeDocument;
var afile = document.fullName;
var filename = afile.name.split('.')[0];
var folder = afile.parent.selectDlg("Export as CSS Layers (images only)...");
if(folder != null)
{
var activeABidx = document.artboards.getActiveArtboardIndex();
var activeAB = document.artboards[activeABidx]; // get active AB
var abBounds = activeAB.artboardRect;// left, top, right, bottom
var docBounds = document.visibleBounds;
activeAB.artboardRect = docBounds;
var options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = true;
var icons = [
{"name": "Icon-512@2x", "size":1024},
{"name": "Icon-512", "size":512},
{"name": "Icon-60@3x", "size":180},
{"name": "Icon-76@2x", "size":152},
{"name": "Icon-72@2x", "size":144},
{"name": "Icon-60@2x", "size":120},
{"name": "Icon-57@2x", "size":114},
{"name": "Icon-50@2x", "size":100},
{"name": "Icon-40@2x", "size":80},
{"name": "Icon-76", "size":76},
{"name": "Icon-72", "size":72},
{"name": "Icon-60", "size":60},
{"name": "Icon-29@2x", "size":58},
{"name": "Icon-57", "size":57},
{"name": "Icon-50", "size":50},
{"name": "Icon-40", "size":40},
{"name": "Icon-29", "size":29}
];
var icon, file;
for(var i = 0; i < icons.length; i++)
{
icon = icons[i];
file = new File(folder.fsName + '/' + icon.name + ".png");
// My App Icon is originally 1024x1024 so that's why I divide height and width by 1024
options.horizontalScale = 100 * (icon.size / document.width);
options.verticalScale = 100 * (icon.size / document.height);
document.exportFile(file,ExportType.PNG24,options);
}
activeAB.artboardRect = abBounds;
}
}
我希望这对其他需要类似东西的人有所帮助。
更新:
关于不同尺寸;更改图标数组以使用高度和宽度而不是大小,例如
var icons = [{"name": "Icon-512@2x", "height":250, "width":125}, ...]
然后将 horizontalScale 更改为使用宽度,将 verticalScale 更改为使用高度。我也对其进行了更改,因此它使用文档高度和宽度而不是硬编码数字。
options.horizontalScale = 100 * (icon.width / document.width);
options.verticalScale = 100 * (icon.height / document.height);
运行 脚本:
通过 volleybologist
- 将上面的代码复制到编辑器中(如Notepad++)
- 另存为 javascript 文件 (.js)
- 打开 Illustrator(已使用 Illustator CC 19.1.0 进行检查并且有效)
- 在 Illustrator 中,转到“文件”>“脚本”>“其他脚本”,然后打开您刚刚保存的 .js 文件
- 会弹出一个对话框,找到并select .js 文件
- 将弹出另一个对话框,要求您为要导出的 png 选择一个位置
- 脚本将 运行 并且图像应位于所选文件夹中
我想导出不同尺寸的 iOS 应用程序图标,但不必为每个尺寸都做!有没有一种方法可以使用 Adobe Illustrator 一次性导出各种不同大小的 PNG?
我自己找到了答案!
http://www.adobe.com/devnet/illustrator/scripting.html
详见上文link;脚本是指示 Illustrator 执行一个或多个任务的一系列命令。
因此,通过使用以下脚本,我能够根据需要导出多个不同尺寸的图像。
#target Illustrator
/**
* export multiple PNG's in different sizes
* @author Alexandros Harvey
*/
// Adapted to export an Illustrator file in various sizes by Alexandros Harvey
// based on how to export images as CSS Layers by CarlosCanto
if (app.documents.length > 0) {
main();
}
else alert('Cancelled by user');
function main() {
var document = app.activeDocument;
var afile = document.fullName;
var filename = afile.name.split('.')[0];
var folder = afile.parent.selectDlg("Export as CSS Layers (images only)...");
if(folder != null)
{
var activeABidx = document.artboards.getActiveArtboardIndex();
var activeAB = document.artboards[activeABidx]; // get active AB
var abBounds = activeAB.artboardRect;// left, top, right, bottom
var docBounds = document.visibleBounds;
activeAB.artboardRect = docBounds;
var options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = true;
var icons = [
{"name": "Icon-512@2x", "size":1024},
{"name": "Icon-512", "size":512},
{"name": "Icon-60@3x", "size":180},
{"name": "Icon-76@2x", "size":152},
{"name": "Icon-72@2x", "size":144},
{"name": "Icon-60@2x", "size":120},
{"name": "Icon-57@2x", "size":114},
{"name": "Icon-50@2x", "size":100},
{"name": "Icon-40@2x", "size":80},
{"name": "Icon-76", "size":76},
{"name": "Icon-72", "size":72},
{"name": "Icon-60", "size":60},
{"name": "Icon-29@2x", "size":58},
{"name": "Icon-57", "size":57},
{"name": "Icon-50", "size":50},
{"name": "Icon-40", "size":40},
{"name": "Icon-29", "size":29}
];
var icon, file;
for(var i = 0; i < icons.length; i++)
{
icon = icons[i];
file = new File(folder.fsName + '/' + icon.name + ".png");
// My App Icon is originally 1024x1024 so that's why I divide height and width by 1024
options.horizontalScale = 100 * (icon.size / document.width);
options.verticalScale = 100 * (icon.size / document.height);
document.exportFile(file,ExportType.PNG24,options);
}
activeAB.artboardRect = abBounds;
}
}
我希望这对其他需要类似东西的人有所帮助。
更新:
关于不同尺寸;更改图标数组以使用高度和宽度而不是大小,例如
var icons = [{"name": "Icon-512@2x", "height":250, "width":125}, ...]
然后将 horizontalScale 更改为使用宽度,将 verticalScale 更改为使用高度。我也对其进行了更改,因此它使用文档高度和宽度而不是硬编码数字。
options.horizontalScale = 100 * (icon.width / document.width);
options.verticalScale = 100 * (icon.height / document.height);
运行 脚本: 通过 volleybologist
- 将上面的代码复制到编辑器中(如Notepad++)
- 另存为 javascript 文件 (.js)
- 打开 Illustrator(已使用 Illustator CC 19.1.0 进行检查并且有效)
- 在 Illustrator 中,转到“文件”>“脚本”>“其他脚本”,然后打开您刚刚保存的 .js 文件
- 会弹出一个对话框,找到并select .js 文件
- 将弹出另一个对话框,要求您为要导出的 png 选择一个位置
- 脚本将 运行 并且图像应位于所选文件夹中