You are on page 1of 1

0.4 Version History Image First Javascript D. Spanton. /* - Pre-Flight v1.1 by version.

Expanded to work on more than one image at a t 0.5 ime.- Errors are reported to a script UI window, rather than to an alert windo w. This to be done at once without the report running offscreen. It also allows allows for more images 0.6 - document. be cut & an extra channel the report data toerror whenpaste to another is selected and histogram data is Corrected called. Expanded on white/black reporting to now give percentage details in RGB 0.9 0.8 0.7 - Expanded toreport tohowoutputis nowtxtcarriage returnhaveflags values gr composite channel.added tohas(now'Ok'imagesPCforof the totalonly desktop. Saving the provideprevent correct optionalon the Output window windowananto400pixels by changed.toa users Larger outputwhite text.many reporting fileopen'Nowbutton. Scrollbar ofdisplaytextblack 'no a out800pixels).exit. errors. Multiline moved Threshold nosLayers now and desktop button a to documents via error. users issue. 1.0 - Expanded to provide a eater than 0.5% of the image. check on image filesize. Flags if an image is unde r 50 andstate.120MBsonlyit's uncompressed, flattened images that have no extra over Will in check flat, RGB or Grayscale alpha channels. to provide a check on image type/extension. If an image is anyt Expanded 1.1 hing-butImage size tolerances slackened by 0.25MB at the lower end (and upper en Error infile, it will be size calculation corrected. a TIFF Grayscale image flagged. var app.preferences.rulerUnits = Units.PIXELS //make sure */ errState = false //overall error state. determines which final to pixels. d for Grayscale). image size error messages clarified.prefs are setmessage is di Grayscale var addName = false //individual error state for each file. detirmines whether t splayed } add filename= 0 > = to {unctionrunCheck() problems were how many if(documents.lengthfunction globaldetected." //initialize=0;to //used no displayvariables ") var message=nosLayersarelistdocuments open. files have //was olsenosErrorshistoerror app.activeDocument.layers.lengtherrors with layer secti f histW0 e okmessage """No 0) histBB histGB histRB histWB var alert("There runCheck() on, now //start looppremessagethroughto background/base layer { for(aby 1; a to cycle too, so allto ++)documentsline used = activeDocument =document open =next in here. app.activeDocument.activeLayer // <= active documents[(a-1)] varsets =activelayer has been app.activeDocument.layers[nosLa addName documents.length; a therelocated //change false "" histo section yers - 1] colModeArr / colModeStr app.activeDocument.bitsPerChannel e colMode }/check for and=colMode.toString()16 Bit {lsebitDepth=colModeStr.split('.') //split parts mode to mode if(bitDepth=colourdepth vardeselects==app.activeDocument.modeBit colourof colourstring //check image=bit==mode"BitDepth: 32//turn\r" app.activeDocument.selection.deselect(); \r" // colModeArr BitsPerChannelType.SIXTEEN) if(bitDepth newBitsPerChannelType.THIRTYTWO) addName= selections on document premessage true errState =true"Bit Depth: +=Array() information intovar colModeOut = colModeArr[1] //retrieve useful part of colour an array mode to string {/check for=channels in&& nosChaGRAYSCALE1) + " (in+RGB) \r" \ i if(colModeOut ==="RGB""Colour&& nosCha+>"GRAYSCALE")GRAYSCALE) var / nosCha }f(colModeOutapp.activeDocument.channels.length addName "GRAYSCALE"and > 3)!= colModeOut "\r" premessage true RGB Mode: errState =true"Channels: " +"nosCha != += colModeOut images. r" / }/checks selected channels are the main channels, and changes th em if not. //this is needed in order for the whites/blacks check to work co rrectly. { if(colModeOut == "RGB" && nosCha > 3) if(app.activeDocument.activeChannels[0] != app.activeDoc ument.channels[0]) { { chArra<3; a++) app.activeDocument.channels[a for(a=0;chArr[a]Array(); var = new = ]; { if(colModeOut ==a"GRAYSCALE" && nosCha > 1) / }/check as above}but for GRAYSCALE if(app.activeDocument.activeChannels[0] !==app.activeDoc } app.activeDocument.selection.deselect(); pp.activeDocument.activeChannels chArr; ument.channels[0]) { { chArra<1; a++) app.activeDocument.channels[a for(a=0;chArr[a]Array(); var = new = ]; { if(colModeOut ==}"RGB") / }/check for whites over 250 in RGB and GRAYSCALE images. passi histo(255,254,253,252,251); //call histo function, } app.activeDocument.selection.deselect(); app.activeDocument.activeChannels = chArr; ng top 5 values { if(histW0 > 0.5)==true"Whites: " + histW0 + " % of image premessage += errState true addName is 255 \r" {f(histWB > 0.5)==true"Whites: " + histWB + " % of image i } premessage += errState true addName is 251 or more \r" {lse if(histRB >=0.5 "Whites: > 0.5 more in R, 0.5) B e } premessage += errState true addName =true histGB 251 or histBB > G or channel" + "\r" }f(colModeOut ==>"GRAYSCALE") RGBhistoGRAYSCALE images. bottom if(colModeOut addName =true"Whites: 251 or higher \r" / { i/check for blacks0.5) =5//call and function, passing histo(0,1,2,3,4); true var w251errState in } { if(w251 premessage += "RGB") = under app.activeDocument.channels[0].histogram[251] 5 values { if(histW0 > 0.5)==true"Blacks: " + histW0 + " % of image premessage += errState true addName is 0 \r" {f(histWB > 0.5)==true"Blacks: " + histWB + " % of image i } premessage += errState true addName is 4 or less \r" {lse if(histRB >=0.5 "Blacks: > 0.5lesshistBB > 0.5) ch e } premessage += errState true addName =true histGB 4 or in R, G or B annel" + "\r" }f(colModeOut>==="GRAYSCALE") "Blacks: 4multiple layers \r" var if(nosLayers= app.activeDocument.layers[nosLayers \r" / { bgLayer background layer i/check for layerstrue"Layers: Contains or lower - 1].isBackgro addName=0.5) var w4>1)app.activeDocument.channels[0].histogram[4] premessage true errStateerrState true } { if(w4 addName ==true premessage += = += undLayer if(nosLayers == 1 true"Layers: No Background Layer \r" / } {/check file size=&& bitDepth == BitsPerChannelType.EIGHT) //che if(!bgLayer) addName = true premessage errState += ck image is flat{and 8-bit if(colModeOut == "RGB" && nosCha == 3) //check RGB image has no extra alpha channels { var hght ==activeDocument.height mbsize (bsize/1024)/1024 bsize =(hght * wdth) * 3 wdth activeDocument.width//calculate uncom pressed filesize of image. mbsize = mbsize * 100 //shorten to 2 decimal pla Math.floor(mbsize) / ces (round down). { if(mbsize < 49.75)true"Filefor images too small" premessage += errState true addName == //error Size: " + mbsize + (too small) \r" e }lse if(mbsize > 120) //error for images too lar ge { premessage += errState true addName ==true"File Size: " + mbsize + " (too large) \r" e }lse if(colModeOut == "GRAYSCALE" && nosCha == 1) //chec } k GRAYSCALE image has no{extra alphahght ==activeDocument.height var wdth activeDocument.width//calculate uncom mbsize (bsize/1024)/1024 bsize =(hght * wdth) channels pressed filesize of image. if(mbsize < 15.75)true"Filefor images too small" { premessage += errState true addName == //error Size: " + mbsize + (too small for Grayscale) \r" }lse if(mbsize > 40.25) //error for images too l e arge { premessage += errState true addName ==true"File Size: " + mbsize + " (too large for Grayscale) \r" } { else //error for=unchecked imagesNOT measured due to oth } premessage += errState true addName =true"File Size (due to channels) er issues \r" }lse //error for=unchecked imagesNOT measured dueor bitdepth) { e addName =true"File Size (due to layers to other issue premessage += errState true } s \r" {/check file = fName.split('.') if(fNameArr[1] new"tif")=="TIF") var fName = app.activeDocument.name;Type: Image is a " + fNameAr / } fNameArr extension andtrue"File if(fNameArr[1] != type { != Array() true premessage errState += addName r[1] + " file. \r" / }/add active documents name to message, followed by the errors o } n the current image"\r" + nosErrors"\r" out of " + documents.length + " images w m }essage if(addName == true)premessage += } { message +=+=+1" + app.activeDocument.name + " - \r" nosErrors ere flagged." error message toWindow('dialog',and desktop txt file. { if(errState windwUI window with a and //write var == true)new alert boxpanelto'Imageedittext portion [100,1 //make a = a an Pre-Flight v1.1', 00,500,800]); windw.pnla = windw.add('panel', [10,10,390,640], 'The following were detected:');indw.pnlb = windw.add('group', [10,650,390,690]); windw.pnla.mainTxt = windw.pnla.add('edittext', [10,10,370,610], w '', {readonly:true, multiline:true}) = message; windw.pnlb.btna = windw.pnlb.add('button', [50,10,160,30], 'Clos windw.pnla.mainTxt.text e'); windw.pnlb.btnb = windw.pnlb.add('button', [210,10,320,30], 'Exp ort Report'); windw.pnlb.btna.onClick = function() w } {indw.pnlb.btnb.onClick expRep; //calls function, see 'expRep' //definethis.parent.parent.close(); button behaviour }below. }lse if(errState ==5false) window in composite, R, G, and B channels //histo elert(okmessage) a { function. analyses histogram values windw.show(); //show functionhistRB app.activeDocument.histogram[y]; } //blues histWB app.activeDocument.histogram[x]; //greensvar w1 app.activeDocument.histogram[w]; //reds histW0 = app.activeDocument.height; //blacksvar totalPx +=w1newht;take +byvv,w,x,y and {/write //percentage=/wdimage + *desktop .unctionvar htmessageoftotalPx) w310000; timeHour +z'-' + timeMin + '-' + timeSe / f fileNa (w0 g1 + r2 onr3 r4 histBB w0 r1 * w2 takenbyw4+ histGB app.activeDocument.histogram[z]; this.parent.parent.close(); g4 error expRep()Math.ceil(histW0); histo(v,w,x,y,z).txt g3 b4 timeSec timeMin timeHour timeStamp bB Math.ceil(histGB); b4 (gB to b2 b3 g0 timeStamp.getSeconds(); b2 app.activeDocument.channels[1].histogram[z]; b1 app.activeDocument.channels[1].histogram[y]; gB app.activeDocument.channels[1].histogram[x]; g4 app.activeDocument.channels[1].histogram[w]; g3 histRB/100; g2 Math.ceil(histRB); g1 (rB timeStamp.getMinutes(); rB r0 =timeStamp.getHours(); r4 app.activeDocument.channels[0].histogram[z]; r3 app.activeDocument.channels[0].histogram[y]; r2 app.activeDocument.channels[0].histogram[x]; r1 app.activeDocument.channels[0].histogram[w]; wB histWB/100; w4 Math.ceil(histWB); w3 (wB b1 g2 b3 w2 histW0/100;Date(); r0 app.activeDocument.channels[2].histogram[w]; wd histGB/100; b0 app.activeDocument.channels[2].histogram[z]; g0 app.activeDocument.channels[2].histogram[y]; w0 app.activeDocument.channels[2].histogram[x]; '~/Desktop/PF_report' histBB/100; Math.ceil(histBB); (bB b0 app.activeDocument.channels[0].histogram[v]; app.activeDocument.width; app.activeDocument.channels[2].histogram[v]; app.activeDocument.channels[1].histogram[v]; app.activeDocument.histogram[v]; } c + '.txt'; fileOut.write(message) "windows" fileOut.write("The following -1) fileOut.open("W", fileLineFeed fileOut.lineFeed ="TEXT", f e }ileOut = new File(fileNa) !=were {lse if($.os.search(/windows/i)"????") detected:\r") fileLineFeed = "macintosh"

You might also like