2012-06-29 1 views
0

모든 이미지 유형에 대해 문서를 스캔하고 흑백으로 변환 한 다음 흑백 이미지를 새 폴더로 내 보내는 스크립트가 있습니다.
InDesign CS5/Script : TIFF 및 PNG 이미지를 '흑백으로 변환 할 수 있습니까?


그것은 InDesign에서 이러한 이미지 파일 형식을 보냅니다 것처럼 보인다     JPEG, TIFF, and PNG (가 하지 수출 GIF 파일을한다).

그러나 (이 하지만,는 JPEG 파일이 속성을 가지고있다) InDesign에서 TIFF 및 PNG 파일에 대한 ColorSpace.GRAY 또는 ColorSpaceEnum.GRAY 특성이없는 것 같다.


  • 그래서, 인디자인의 수정 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 

답변

1

을에 TIFF 및 PNG 파일을 변환하는 방법은 무엇입니까 흑백 InDesign의 Extendscript?

아니요.

이 파일 유형에 흑백 변환을 제공하지 않은 이유는 무엇입니까?

그는 그는 오직 하나님 만이 알고 : D

기대 감안할 때

, 차라리 당신이 원하는 형식, 원하는 설정을 사용할 수 있습니다 포토샵이 이미지 작업을 위임 할 것입니다. BridgeTalk 객체를 사용하거나 Ps (applescript for ex)를 실행할 핫 폴더를 가질 수 있습니다. 또는 doScript를 사용하여 os에 따라 applescript 또는 visualbasic을 호출하고 사용자가 가지고있는 변환 도구를 실행할 수 있습니다.

행운을 빈다.

loic

추신 :이 도구도 참조하십시오. 어쩌면 내가 BridgeTalk를 사용하여이 코드의 버전에 노력하고있다 비록 당신이 http://www.rorohiko.com/wordpress/indesign-downloads/color2gray/

+0

흠, 어쨌든 Photoshop에서 파일 서식을 지정하는 것이 더 바람직 할 수 있으므로 'BridgeTalk'개체를 사용하고 있습니다. 여기서는 좋은 참조를 발견했습니다. http : //forums.adobe. co.kr/message/3334670 # 3334670). @Loic! 감사합니다. 내가 알아 냈을 때 내 코드를 게시 할 것이다 ... –

0

그래서 JS로 호출 할 수있는 몇 가지 API를 가지고, 내가 JPEG의에 적용되는 서식은 .BMP의에 적용 할 수 있다는 것을 최근에 발견 , .TIF, .EPS 및 .PNG가 프로그래밍 방식으로 에 의해 파일 확장명을 원하는 형식으로 바꿉니다.

그러나 .PDF의 은 형식이 잘못 지정되어 손상 되었기 때문에을 다른 파일 형식으로 강제 변환 할 수 없습니다. 내가 BridgeTalk를 사용하지 않았지만, 나는 아직도 이것에 찾고

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 


: 여기

몇 가지 수정을 위의 코드와 매우 유사하다 내 작업 코드입니다 여기에 좋은 참조를 발견했습니다 : http://www.kasyan.ho.com.ua/convert_cmyk-rgb_images_to_grayscale.html.

그리고 에 대한 아이디어가 없으면은 원래 이미지를 덮어 씁니다 : http://forums.adobe.com/message/4292613#4292613.

관련 문제