// les photos devront deja êtres reduites a la taille d'exploitation var doc = app.activeDocument; var Path = doc.path; preferences.rulerUnits = Units.PIXELS; preferences.typeUnits = TypeUnits.POINTS; var rUnits = preferences.rulerUnits, tUnits = preferences.typeUnits; var f = new Folder(Path+"/CREA"); if ( ! f.exists ) { f.create() } var s4 =new Folder(Path+"/CREA"+"/V4") if ( ! s4.exists ) { s4.create() } var docName = doc.name; // Gets rid of the extension var docName = docName.substring( 0, docName.indexOf('.') ); NamesaveRef = new File( f + "/"+docName+".jpg"); var NewfileRef = new File( NamesaveRef ); NamesaveRefv4 = new File( s4 + "/"+docName+".jpg"); var NewfileRefv4 = new File( NamesaveRefv4 ); NamesaveRef4res = new File( s4 + "/"+docName+".png"); var NewfileRef4res = new File( NamesaveRef4res ); NamesaveRef2 = new File( f + "/"+docName+".png"); var NewfileRef2 = new File( NamesaveRef2 ); var ratio = parseFloat(doc.width/doc.height); var L=doc.width; var H =doc.height; // quality/size constraints if (ratio>4,5){ switch(L) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// header {case("930"): var w = 930; // new file width var MaxSz = 102400; // max. 100Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 10) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; case("700"): ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bandeau large var w = 700; // new file width var MaxSz = 102400;// max. 100Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 20) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; }} else{ switch(L) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////V4 acceuil smartphone {case("2028"): var w = 2028; // new file width var MaxSz = 1126400; // max. 1100Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4 = new File( NewfileRefv4 ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 50) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 50 (this shouldn't need to happen) } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V4 acceuil tablette case("2514"): var w = 2514; // new file width var MaxSz = 1024000; // max. 1000Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4= new File( NewfileRefv4 ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 50) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 50 (this shouldn't need to happen) } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V4 bandeau desktop case("669"): var w = 669; // new file width var MaxSz = 204800; // max. 200Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4 = new File( NewfileRefv4 ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 50) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 50 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V4logo case("288"): var w = 288; // new file width var MaxSz = 30720; // max. 30Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4 = new File( NewfileRefv4 ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 10) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// v4 acceuil generic case("938"): var w = 938; // new file width var MaxSz = 204800; // max. 200Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4 = new File( NewfileRefv4 ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 30) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V4 mailing case("550"): var w = 550; // new file width var MaxSz = 102400; // max. 100Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4 = new File( NewfileRefv4 ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 30) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// v4 acceuil generic case("938"): var w = 938; // new file width var MaxSz = 204800; // max. 200Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRefv4, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRefv4.length > MaxSz) { Qlt = Qlt - x; NewfileRefv4 = new File( NewfileRef ); NewfileRefv4.remove(); ExpWeb(NewfileRefv4, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 30) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRefv4.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V3 acceil stantdard case("930"): var w = 930; // new file width var MaxSz = 256000; // max. 250Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 30) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V3 PRODUIT case("386"): var w = 386; // new file width var MaxSz = 102400; // max. 100Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 50) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V3categorie case("700"): var w = 700; // new file width var MaxSz = 358400; // max. 300Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 50) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V3 bandeau court case("344"): var w = 344; // new file width var MaxSz = 76800; // max. 75Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 50) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V3logo case("200"): var w = 200; // new file width var MaxSz = 30720; // max. 30Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step // resize the image to the right width doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef.length > MaxSz) { Qlt = Qlt - x; NewfileRef = new File( NewfileRef ); NewfileRef.remove(); ExpWeb(NewfileRef, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 10) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// V3logo resp case("300"): var w = 300; // new file width var MaxSz = 30720; // max. 30Kb var Qlt = 100; // initial quality 100 var x = 1; // decreasing step if(docName.match(/(V4)/ig)){ doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef4res, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef4res.length > MaxSz) { Qlt = Qlt - x; NewfileRef4res = new File( NewfileRef4res ); NewfileRef4res.remove(); ExpWeb(NewfileRef4res, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 10) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef4res.length/1024; FileSz = Math.round(FileSz); } else { doc.resizeImage(UnitValue(w,"px"),null,100,ResampleMethod.BICUBICSHARPER); // Perform the first SaveForWeb Operation ExpWeb(NewfileRef2, Qlt); // Keep trying to save the file with max. Qlt, but under MaxSz while (NewfileRef2.length > MaxSz) { Qlt = Qlt - x; NewfileRef2 = new File( NewfileRef2 ); NewfileRef2.remove(); ExpWeb2(NewfileRef2, Qlt); // Perform a new SaveForWeb Operation, with slightly lower Qlt if (Qlt <= 10) { alert("The file can't be saved with the desired size AND quality."); break // break the loop whenever the quality is as low as 10 (this shouldn't need to happen) // il faut profiter du break pour noter la ref en questrion } } var FileSz = NewfileRef.length/1024; FileSz = Math.round(FileSz); } // close the original file without saving activeDocument.close(SaveOptions.DONOTSAVECHANGES); break; }} function ExpWeb(FileNm, Qlt) { var options = new ExportOptionsSaveForWeb(); options.quality = Qlt; // Start with highest quality (biggest file). options.format = SaveDocumentType.JPEG; // Save Format for the file options.includeProfile = true; doc.exportDocument(File(FileNm), ExportType.SAVEFORWEB, options); } function ExpWeb2(FileNm, Qlt) { var options = new ExportOptionsSaveForWeb(); options.quality = Qlt; // Start with highest quality (biggest file). options.format = SaveDocumentType.PNG; // Save Format for the file options.includeProfile = true; doc.exportDocument(File(FileNm), ExportType.SAVEFORWEB, options); }
... View more