Fixed filenames with whitespace (output with underscore), clear cache (purge all) to help stop the 'scratch disk full', close photoshop when script ends

master
Jonathan Chan 2 years ago
parent 54a21f1964
commit 8dbeca747c

@ -28,9 +28,9 @@ var site_names = csv_data.toString().split(",")
// Retrieve images parent directory from CoastSnap_Sites.csv
var parent_folder_path = File(site_names[9]);
var batch_images_to_register = []; // Used in exportLayersToJPEG
// Loop through sites
for(var i=5; i<site_names.length; i+=5) {
var site_name = site_names[i];
@ -63,9 +63,12 @@ for(var i=5; i<site_names.length; i+=5) {
for (var k = 0; k < images_to_register.length; k += batch_size) {
batch_register_images(k, site_path, site_name, images_to_register, target_image, seed_images);
}
}
}
// Close Photoshop
executeAction(app.charIDToTypeID('quit'), undefined, DialogModes.NO);
// This is the main function, responsible for calling photoshop functions
// in a sequential order to register all_images
@ -100,6 +103,7 @@ function batch_register_images(batchIndex, site_path, site_name, images_to_regis
exportLayersToJPEG(target_width, target_height, batch_images_to_register, seed_images); // Won't overwrite images that already exist
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
purgeCache(); // To help avoid the scratch disk from becoming full
}
@ -111,13 +115,19 @@ function imagesNotRegistered(site_images_all, photoshop_images) {
for (var i = 0; i < site_images_all.length; i ++) { // For each site image
var isRegistered = false;
for (var j = 0; j < photoshop_images.length; j++ ) { // Check if already exists in photoshop images
var site_name_CHECK = site_images_all[i].name.slice(0,-4) + '_CHECK.jpg';
if((site_images_all[i].name.toString() == photoshop_images[j].name.toString()) || (site_name_CHECK.toString() == photoshop_images[j].name.toString())) {
//var site_name_CHECK = site_images_all[i].name.slice(0,-4) + '_CHECK.jpg';
var site_image = site_images_all[i].name.toString()
site_image = site_image.replace("%20", "_")
if((site_image == photoshop_images[j].name.toString())) {
isRegistered = true;
break;
}
}
if(!isRegistered) { // If it doesn't, register it
//site2add = site_images_all[i].toString()
//var s = site2add.replace("%20", "_") // getFiles() reads in white space as "%20". So convert to "_"
//alert(s)
//var s = File(site_image);
site_images.push(site_images_all[i]);
}
}
@ -287,7 +297,10 @@ function exportLayersToJPEG(target_width, target_height, batch_images_to_registe
// }
for (var i = 0; i < batch_images_to_register.length; i++ ) { // Loop through batch_images_to_register
if(batch_images_to_register[i].toString() == name.toString()) {
var image2register = batch_images_to_register[i].toString();
image2register = image2register.replace("%20", " ")
if(image2register == name.toString()) {
app.activeDocument.activeLayer = el.layers.getByName(name);
var theBounds = app.activeDocument.activeLayer.bounds;
@ -316,7 +329,10 @@ function exportLayersToJPEG(target_width, target_height, batch_images_to_registe
activeDocument.mergeVisibleLayers();
}
//activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
var saveFile = File(path +"/Photoshop/"+year+"/"+lname);
output_file_path = path +"/Photoshop/"+year+"/"+lname;
output_file_path = output_file_path.replace(" ", "_")
var saveFile = File(output_file_path);
SaveJPEG(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
@ -342,4 +358,16 @@ function SaveJPEG(saveFile){
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
// Not sure if this does anything
function purgeCache() {
var idPrge = charIDToTypeID( "Prge" );
var desc335 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var idPrgI = charIDToTypeID( "PrgI" );
var idClpb = charIDToTypeID( "Clpb" );
desc335.putEnumerated( idnull, idPrgI, idClpb );
executeAction( idPrge, desc335, DialogModes.NO );
}
Loading…
Cancel
Save