adobe - InDesign CS5 / Script: Can I convert TIFF and PNG images to `black and white`? -
i have script scans document image types, converts them black , white, , exports black , white images new folder.
seems if indesign export these image file-formats:
jpeg, tiff, , png
(it not export gif files). however, seems indesign doesn't have
colorspace.gray
or colorspaceenum.gray
properties tiff , png files (it does have property jpeg files, though). so, there way convert tiff , png files black , white in indesign's extendscript?
if there not, reasoning not providing black , white conversion these file types?
here code, of exports black , white jpeg files:
var document = app.activedocument; var newfolder = createfolder(document); // if subdirectory dne, create folder function below saveallimages(document, newfolder); // function below function createfolder(doc) { try { /* * type-casting filepath property (of type object) string type; * must string type concatenate subdirectory variable (also of type string) */ var docpath = string(doc.filepath); var subdirectory = "/black , white images"; } catch(e) { alert(e.message); exit(); } var imagesfolder = docpath + subdirectory; // concatenating 2 variables if(!folder(imagesfolder).exists) { folder(imagesfolder).create(); } return imagesfolder; // instantiation outside of function } // end of function createfolder function saveallimages(doc, folder) { var imgs = doc.allgraphics; var filename = ""; var img = ""; var imgtype = ""; for(var = 0; < 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 determined here (.tif, .jpg, .png, etc..) alert("this " + imgtype + " file."); /* * array image options, instantiated function below; * options[0] "maximum" image quality property, & * options[1] "gray" image conversion property; */ var options = converttoblackandwhite(imgtype); // each image exported new folder here, file type switch(imgtype) { case "gif": alert("this script cannot convert , export 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 type switch statement."); break; } // end of switch statement } // end of if statement } // end of loop } // end of function saveallimages function converttoblackandwhite(filetype) { // array image-quality , color-conversion values var settings = []; // each image exported new folder here, 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; // instantiation outside of function } // end of function converttoblackandwhite
so, there way convert tiff , png files black , white in indesign's extendscript?
not aware of.
if there not, reasoning not providing black , white conversion these file types?
he god knows :d
given expectations, rather delegate these image operations photoshop can use formats want, settings want. can either use bridgetalk object or have hotfolder run ps ( applescript ex ). or use doscript call applescript or visualbasic depending on os , have them run conversion tool might have.
good luck.
loic
ps: see tool also. maybe has api can call js http://www.rorohiko.com/wordpress/indesign-downloads/color2gray/
Comments
Post a Comment