0

すべての画像タイプのドキュメントをスキャンし、それらをすべて白黒に変換してから、白黒画像を新しいフォルダーにエクスポートするスクリプトがあります。


InDesign はこれらの画像ファイル形式をエクスポートするようです:   JPEG, TIFF, and PNG( GIF ファイルはエクスポート しません)。

ただし、InDesign にはTIFF および PNG ファイルのColorSpace.GRAYまたはプロパティがないようです (ただし、JPEG ファイルにはこのプロパティがあります)。 ColorSpaceEnum.GRAY


  • では、InDesign の Extendscript で TIFF および PNG ファイルを白黒に変換する方法はありますか?

  • 存在しない場合これらのファイル タイプに白黒変換を提供しない理由は何ですか?



これが私のコードです。現在、白黒のJPEGファイルのみをエクスポートしています。

var document = app.activeDocument;
var newFolder = createFolder(document); // if subdirectory DNE, create this folder with the function below

saveAllImages(document, newFolder); // with the function below



function createFolder(doc)
{
    try
    {
      /*
         * type-casting the filePath property (of type object) into a String type;
         * must be a String type to concatenate with the subdirectory variable (also of type String)
         */
        var docPath = String(doc.filePath);
        var subdirectory = "/BLACK AND WHITE IMAGES";
    }
    catch(e)
    {
        alert(e.message);
        exit();
    }

    var imagesFolder = docPath + subdirectory; // concatenating the two variables
    if(!Folder(imagesFolder).exists)
    {
        Folder(imagesFolder).create();
    }

    return imagesFolder; // for instantiation outside of this function

} // end of function createFolder



function saveAllImages(doc, folder)
{
    var imgs = doc.allGraphics;
    var fileName = "";
    var img = "";
    var imgType = "";

    for(var i = 0; i < imgs.length; i++)
    {
        if(imgs[i].itemLink != null)
        {
            fileName = imgs[i].itemLink.name;
            img = new File(folder + "/" + fileName); // each image instantiated here
            imgType = imgs[i].imageTypeName; // image type is determined here (.tif, .jpg, .png, etc..)

            alert("This is a " + imgType + " file.");

            /*
                * array for image options, instantiated from the function below;
                * options[0] is the "MAXIMUM" image quality property, &
                * options[1] is the "GRAY" image conversion property;
                */
            var options = convertToBlackAndWhite(imgType);

            // each image exported to the new folder here, by file type
            switch(imgType)
            {
                case "GIF":
                    alert("This script cannot convert and export the GIF file:\n\t" + fileName + " !");
                    break;

                case "TIFF":

            case "EPS":

                case "JPG":
                    options[0]; // maximum image quality
                    options[1]; // black & white conversion

                    imgs[i].exportFile(ExportFormat.JPG, img, false);
                    break;

                case "PNG":
                    options[0]; // maximum image quality
                    options[1]; // black & white conversion

                    imgs[i].exportFile(ExportFormat.PNG_TYPE, img, false);
                    break;

                default:
                    alert("\tUnlisted image type: " + imgType + "!\nAdd this type to the switch statement.");
                    break;
            } // end of switch statement

        } // end of if statement
    } // end of for loop

} // end of function saveAllImages



        function convertToBlackAndWhite(fileType)
        {
            // array for image-quality and color-conversion values
            var settings = [];

            // each image exported to the new folder here, by file type
            switch(fileType)
            {
                case "TIFF":

                case "PNG":

            case "EPS":

                case "JPG":
                    settings[0] = "app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM"; // maximum image quality
                    settings[1] = "app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY"; // black & white conversion
                    break;

                default:
                    break;

            } // end of switch statement

            return settings; // for instantiation outside of this function

        } // end of function convertToBlackAndWhite
4

2 に答える 2

1

では、InDesign の Extendscript で TIFF および PNG ファイルを白黒に変換する方法はありますか?

私が知っているわけではありません。

存在しない場合、これらのファイル タイプの白黒変換を提供しない理由は何ですか?

彼は神のみぞ知る :D

あなたの期待を踏まえて、私はこれらの画像操作を Photoshop に任せたいと思います。Photoshop では、必要な形式や設定を使用できます。BridgeTalk オブジェクトを使用するか、Ps ( ex の場合は applescript ) を実行するホットフォルダーを使用できます。または、OSに応じてdoScriptを使用してapplescriptまたはvisualbasicを呼び出し、それらに変換ツールを実行させることもできます。

幸運を。

ロイク

PS: このツールも参照してください。たぶん、JSで呼び出すことができるAPIがあります http://www.rorohiko.com/wordpress/indesign-downloads/color2gray/

于 2012-06-29T09:14:08.527 に答える
0

したがって、私は を使用するこのコードのバージョンに取り組んできましたが、BridgeTalk最近、JPEG に適用されるフォーマットは、後でプログラムでファイル拡張子の名前を変更することにより、.BMP、.TIF、.EPS、および .PNG に適用できることを発見しました。希望のフォーマットに。

ただし、.PDFを別のファイル形式に変換する ことはできません。形式が正しくなく、破損するためです。

これは私の作業コードです。これは上記のコードにかなり似ていますが、いくつかの変更が加えられています。

var document = app.activeDocument;
var newFolder = createFolder(document); // if subdirectory images DNE, create this folder with the function below

saveAllImages(document, newFolder); // with the function below

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function createFolder(doc)
{
    try
    {
      /*
         * type-casting the filePath property (of type object) into a String type;
         * must be a String type to concatenate with the subdirectory variable (also of type String)
         */
        var docPath = String(doc.filePath);
        var subdirectory = "/BLACK AND WHITE IMAGES";
    }
    catch(e)
    {
        alert(e.message);
        exit();
    }

    var imagesFolder = docPath + subdirectory; // concatenating the two variables
    if(!Folder(imagesFolder).exists)
    {
        Folder(imagesFolder).create();
    }

    return imagesFolder; // for instantiation outside of this function

} // end of function createFolder

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function saveAllImages(doc, folder)
{
    var imgs = doc.allGraphics;
    var fileName = "";
    var img = "";
    var imgType = "";

    for(var i = 0; i < imgs.length; i++)
    {
        if(imgs[i].itemLink != null)
        {
            fileName = imgs[i].itemLink.name;
            var str = fileName.substr(0, fileName.length - 4) + ".tif"; // converting all file types to .TIF
            img = new File(folder + "/" + str); // each image instantiated here
            imgType = imgs[i].imageTypeName; // image type is determined here (.tif, .jpg, .png, etc..)

            //alert("The file \"" + fileName + "\"\n\tis a " + imgType + " file.");

            /*
                * array for image options, instantiated from the function below;
                * options[0] is the "MAXIMUM" image quality property, &
                * options[1] is the "GRAY" image conversion property;
                */
            var options = convertToBlackAndWhite(imgType);

            // each image exported to the new folder here, by file type
            switch(imgType)
            {
                case "GIF":
                    alert("This script cannot convert and export the GIF file:\n\t" + fileName + " !");
                    break;

                case "Adobe PDF":
                    // PDF file type does not have the maximum image quality property
                    options[1]; // black & white conversion

                    imgs[i].exportFile(ExportFormat.PDF_TYPE, img, false);
                    break;

                case "EPS":
                    // PDF file type does not have the maximum image quality property
                    options[1]; // black & white conversion

                    imgs[i].exportFile(ExportFormat.EPS_TYPE, img, false);
                    break;

                case "Windows Bitmap":
                case "PNG":
                case "TIFF":
                case "JPEG":
                    options[0]; // maximum image quality
                    options[1]; // black & white conversion

                    imgs[i].exportFile(ExportFormat.JPG, img, false);
                    break;

                default:
                    alert("\tUnlisted image type: " + imgType + "!\nAdd this type to the switch statement.");
                    break;
            } // end of switch statement

            replaceWithNewImage(doc, fileName, img); // with the function below

        } // end of if statement
    } // end of for loop

} // end of function saveAllImages

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        function convertToBlackAndWhite(fileType)
        {
            // array for image-quality and color-conversion values
            var settings = [];

            // each image exported to the new folder here, by file type
            switch(fileType)
            {
                case "Adobe PDF":
                    settings[0] = ""; // PDF file type does not have the maximum image quality property
                    settings[1] = "app.pdfExportPreferences.pdfColorSpace = PDFColorSpace.GRAY"; // black & white conversion
                    break;

                case "EPS":
                    settings[0] = ""; // EPS file type does not have the maximum image quality property
                    settings[1] = "app.epsExportPreferences.epsColorSpace = EPSColorSpace.GRAY"; // black & white conversion
                    break;

                case "Windows Bitmap":
                case "PNG":
                case "TIFF":
                case "JPEG":
                    settings[0] = "app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM"; // maximum image quality
                    settings[1] = "app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY"; // black & white conversion
                    break;

                default:
                    break;
            } // end of switch statement

            return settings; // for instantiation outside of this function

        } // end of function convertToBlackAndWhite


私は使用しませんでしたがBridgeTalk、私はまだこれを調べており、ここで良いリファレンスを見つけました: http://www.kasyan.ho.com.ua/convert_cmyk-rgb_images_to_grayscale.html . また、元の画像を上書き しない

というアイデアについては、http: //forums.adobe.com/message/4292613#4292613を参照してください。

于 2012-07-05T23:03:49.217 に答える