您当前的位置: 首页 > 

插件开发

暂无认证

  • 5浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

illustrator插件-将位图矢量化-转为SVG-AI插件-临摹-范例

插件开发 发布时间:2022-09-05 08:00:00 ,浏览量:5

文章目录
    • 1.illustrator脚本
      • 1.1.app.activeDocument
      • 1.2.PlacedItem.trace()
    • 2.位图矢量化-范例1
    • 3.位图临摹-范例2
    • 4.作者答疑

1.illustrator脚本

  脚本由JavaScript语言形式表达,包括一系列表示illustrator内部对象的属性和方法。通过调用这些对象,来实现illustrator内部功能的自动化处理和批处理。脚本分为两部分,一部分是常规的ExtendScript,另一部分是illustrator内置对象。学习如何开发illustrator脚本插件,必须对涉及到的这两块内容有充分的了解,前者作者推荐,JavaScript Tools Guide CC这个文档来学习,下载地址:https://download.csdn.net/download/m0_67316550/86502055,后者推荐,Illustrator_JavaScript_Scripting_Reference_2017,这个文档来了解illustrator软件常用的对象,掌握其调用方式,编写作业功能。下载地址:https://download.csdn.net/download/m0_67316550/86502072

1.1.app.activeDocument

  app是脚本运行环境的内置对象,代表整个应用程序。在Illustrator_JavaScript_Scripting_Reference_2017这个文档中可以查到。如下所示:

app是Adobe®Illustrator®应用程序对象,使用预定义的全局应用程序对象引用,其中包含所有其他Illustrator对象。

  activeDocument是一个Document对象。表示当前AI文档。文档包含在Application对象中。

那些以单词“default”开头的属性是默认的文档设置。 确保只在文档打开时修改这些默认属性。 注意,如果在创建新对象之前将默认属性设置为所需的值,就可以简化脚本,消除了指定具有默认属性的特定属性(如fillColor和stroke)的需要。 文档的颜色空间、高度和宽度只能在创建文档时设置。 不能在现有文档中修改这些属性。

1.2.PlacedItem.trace()

  该函数将置入对象转为矢量对象。使用默认选项将此对象的栅格图形转换为矢量图形。 将放置的图像重新排序到插件组的源图像中,并将其转换为一组与原始图像相似的填充或描边路径。 创建并返回引用tracingObject对象的pluginItem对象。 该矢量化函数,相当于菜单命令临摹,如下图所示: 在这里插入图片描述

2.位图矢量化-范例1

本文展示一个批量将位图转换为SVG矢量图的脚本过程,供读者参考,代码如下所示:

// Main Code [Execution of script begins here]

// Collectable files
var COLLECTABLE_EXTENSIONS = ["bmp", "gif", "giff", "jpeg", "jpg", "pct", "pic", "psd", "png", "tif", "tiff"];
var destFolder, sourceFolder;

// Select the source folder
sourceFolder = Folder.selectDialog('Select the SOURCE folder...', '~');
//sourceFolder = new Folder("C:/Users//Desktop/1");

if (sourceFolder != null) {
    // Select the destination folder
    destFolder = Folder.selectDialog('Select the DESTINATION folder...', '~');
    //destFolder = new Folder("C:/Users//Desktop/2");
}

if (sourceFolder != null && destFolder != null) {
    //getting the list of the files from the input folder
    var fileList = sourceFolder.getFiles();
    var errorList;
    var tracingPresets = app.tracingPresetsList;

    var TraceList = [{
            TracePreset: "ImgDraw_黑白",
            SaveName: "black"
        }, {
            TracePreset: "ImgDraw_灰度",
            SaveName: "gray"
        }, {
            TracePreset: "ImgDraw",
            SaveName: "color"
        }
    ];

    // 新建一个文档
    var doc = app.documents.add();
    for (var i = 0; i             
关注
打赏
1665481431
查看更多评论
0.1045s