首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSFL -批量导出不同大小的PNG

JSFL -批量导出不同大小的PNG
EN

Stack Overflow用户
提问于 2013-04-27 03:42:57
回答 1查看 3.9K关注 0票数 0

我使用闪光CS6,我需要保存一个32位的矢量图形在9个不同的大小。

代码语言:javascript
复制
16
32
36
48
72
114
128
150
480

如何在JSFL中为其编写批量导出脚本?

JSFL Docs格式

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-28 05:18:19

我有一个脚本,可以做你想做的事情。看起来您并没有真正尝试编写任何代码或展示任何研究尝试,所以如果您最终使用了这个脚本,我将不胜感激。

在舞台上选择影片剪辑,然后运行此命令。

Andrew Doll - Multiple Size PNG Exporter

注意:在运行此脚本之前,请使用所需的PNG导出设置导出一个PNG图像。

fl.getDocumentDOM.exportPNG()接受3个参数。第一个是文件名的字符串。第二个参数是一个布尔值,用于指定是使用当前的PNG发布设置(true)还是显示“Export PNG”对话框(false)。第三个参数是一个布尔值,它指定是仅导出当前帧(true)还是导出所有帧,每个帧都作为单独的PNG文件导出(false)。

由于此脚本将第二个参数设置为true,因此只需确保PNG导出设置已经设置为32位PNG即可。

代码语言:javascript
复制
// Multiple Size PNG Exporter
// Copyright © 2014 Andrew Doll
// http://www.andrewdollanimation.com/

/* NOTE:Before running this script export one PNG image using the desired PNG export settings.  fl.getDocumentDOM.exportPNG() accepts 3 
** paramaters. The first is the string for the file name.  The second is a Boolean value that specifies whether to use the current PNG 
** publish settings (true) or to display the Export PNG dialog box (false).  The third is a Boolean value that specifies whether to export 
** only the current frame (true) or to export all frames, with each frame as a separate PNG file (false).  Since this script sets the
** second paramater to true just be sure that the PNG export settings are already set to 32 bit PNG.
*/

// Check to see if there is a file open first.
var dom = fl.getDocumentDOM();
if (dom == null)
{
    alert("Please open a file.");
}
else
{
    var sel = [];
    var exportSizeArray = [];
    var folderURI = "";
    var folderLocation = "";
    var pngFileName = "";
    var URI = "";
    var selWidth;
    var selHeight;
    var sideToUse;
    var scaleAmount;

    function setupExportFolder()
    {
        // Create a folder and file name for the PNG files.
        folderLocation = fl.browseForFolderURL("Select a folder.");
        if(folderLocation != null)
        {
            folderURI = folderLocation + "/PNG Exports";
            FLfile.createFolder(folderURI);
            pngFileName = prompt("What would you like to name the png files?");
        }
    }

    // Check if a movie clip on the stage is selected to export PNG images.
    var selectionCheck = dom.selection;
    if(!selectionCheck || !selectionCheck.length)
    {
        alert("Please select a movie clip on the stage.");
    }
    else
    {
        // Set up export sizes in this array.
        exportSizeArray = [16, 32, 64, 128, 256, 512, 1024];

        // Setup export folder
        setupExportFolder();

        if(folderLocation != null && pngFileName != null)
        {
            // Copy the selected artwork from the stage.
            sel = dom.selection[0];
            dom.clipCopy();

            // Calculate the amount to scale the symbol by based on the longest side.
            function calculateScaleAmount(selWidth, selHeight)
            {
                if(selWidth >= selHeight)
                {
                    sideToUse = selWidth;
                }
                else
                {
                    sideToUse = selHeight;
                }
                scaleAmount = exportSizeArray[i]/sideToUse;
                return scaleAmount;
            }

            // Set the width and height of the symbol. Handle this with the size array.
            for (var i = 0; i < exportSizeArray.length; i++)
            {
                // Create a new FLA document.
                fl.createDocument();
                dom = fl.getDocumentDOM();

                // Resize the document to the current export size.
                dom.width = exportSizeArray[i];
                dom.height = exportSizeArray[i];

                // Paste the artwork to the stage.
                dom.clipPaste(true);
                sel = dom.selection[0];
                dom.setAlignToDocument(true);
                selWidth = sel.width;
                selHeight = sel.height;
                calculateScaleAmount(selWidth, selHeight);

                // Scale the artwork to the size of the stage based on the largest side.
                dom.scaleSelection(scaleAmount, scaleAmount, "center");

                // Align to the center of the stage.
                dom.align("vertical center", true);
                dom.align("horizontal center", true);

                // Output the image.
                URI = folderURI + "/" + pngFileName + "_" + exportSizeArray[i] + " x " + exportSizeArray[i] + "_";
                dom.exportPNG(URI, true, true);

                // Close the temporary FLA without saving.
                dom.close(false);
            }
        }
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16244060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档