Illustrator脚本中的SVG保存选项

时间:2019-01-18 13:56:51

标签: javascript svg adobe jpeg adobe-illustrator

我制作了以下脚本来批量调整大小和将JPG照片集中在SVG文件中:

function container()
{
    var sourceFolder = Folder.selectDialog();  
    var TypeList = prompt("Enter file types to act on","ai,eps,pdf,jpg,png","File Types");      
    var reg = new RegExp("\.(" + TypeList.replace(/,/g, '|') + ")$", 'i');      
    var filesToProcess = sourceFolder.getFiles(reg);  
    var x = 400;  
    var y = 300;  
    var w = 800;  
    var h = 600;  
    var userDesktop = Folder.desktop;    
    var f = new File(userDesktop+'/Satz 2.aia'); // make a file object first, using a string




    function fitObjectToArtboardBounds()
    {
        var idoc = app.activeDocument;
        var layers = idoc.layers;
        var scriptID = "Random Select v0.2";
        var selec = idoc.selection;
        for(var x=0,len=layers.length;x<len;x++)
        {
            layers[x].hasSelectedArtwork = true;
        }


        selec = idoc.selection;
        if (selec.length == 1)
        {
            var docw = idoc.width;
            var doch = idoc.height;
            var activeAB = idoc.artboards[idoc.artboards.getActiveArtboardIndex()]; // get active AB  
            docLeft = activeAB.artboardRect[0];
            docTop = activeAB.artboardRect[1];
            var sel = idoc.selection[0];
            var selVB = sel.visibleBounds;
            var selVw = selVB[2] - selVB[0];
            var selVh = selVB[1] - selVB[3];
            var selGB = sel.geometricBounds;
            var selGw = selGB[2] - selGB[0];
            var selGh = selGB[1] - selGB[3];
            var deltaX = selVw - selGw;
            var deltaY = selVh - selGh;
            if (sel.width > sel.height)
            {
                var newHeight = doch - deltaY;
                var ratio = sel.height / newHeight;
                sel.height = newHeight;
                sel.width = sel.width / ratio;
            }
            else
            {
                var newHeight = doch - deltaY;
                var ratio = sel.height / newHeight;
                sel.height = newHeight;
                sel.width = sel.width / ratio;
            }
            sel.top = (doch / 2) - (sel.height / 2);
            sel.left = (docw / 2) - (sel.width / 2);
            app.doScript('Aktion1', 'Satz 3');
            app.executeMenuCommand('fitall');
        }
        else
        {
            alert("select ONE object before running");
        }
    } 

    var userDesktop = Folder.desktop;    
    var g = new File(userDesktop+'/Satz 4.aia'); // make a file object first, using a string       
    app.loadAction (g); // the argument here is a file object  
    g = new File(userDesktop+'/Satz 3.aia'); // make a file object first, using a string       
    app.loadAction (g); // the argument here is a file object   
      
      
    // Create progress bar  
    var win = new Window("palette", "ProgressBar", [300, 150, 750, 280]);     
        win.pnl = win.add("panel", [10, 10, 440, 120], "Script Progress");    
        win.pnl.progBar = win.pnl.add("progressbar", [20, 35, 410, 60], 0, 100);    
        win.pnl.progBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], "0%");    
        win.pnl.fileLabel = win.pnl.add("statictext", [20, 65, 410, 80], "File processed: none");    
    win.show();  
      
      
    // Increment through the files  
    for (var i=0; i < filesToProcess.length; i++) {  
        app.open(filesToProcess[i]);  
        app.activeDocument.artboards[0].artboardRect = [x, -y, (x + w), -(y + h)];  
        fitObjectToArtboardBounds();    
        win.pnl.fileLabel.text = "File: " + app.activeDocument.name;   
        app.doScript ('Aktion3', 'Satz 4');   
        app.activeDocument.close();  
        win.pnl.progBar.value = parseInt( (i/filesToProcess.length)*100 );  
            win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";  
            win.update();  
    }  
      
      
    win.pnl.progBar.value = 100;  
    win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";  
    win.update();  
    alert('Done!');   
    win.close(); 
    win.pnl.progBar.value = parseInt( (i/filesToProcess.length)*100 );  
        win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";  
        win.update();  
    win.pnl.progBar.value = 100;  
    win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";  
    win.update();  
    alert('Done!');   
    win.close();  
}
container();

输出文件的大小与原始JPG文件一样大(约5 MB),而最大应为200 kB。

如何缩小尺寸?

我考虑过SVG选项,但是我不知道如何实现,因为脚本中的Saveing部分只是Illustrator动作app.doScript ('Aktion3', 'Satz 4');且不可修改。

有关信息,我认为SVG文件中的JPEG照片是链接的,尽管其尺寸减小到800x600 px,但其DPI仍然很高(> 400)。

预先感谢您的帮助!

0 个答案:

没有答案