-
-
Save rolftimmermans/936eb3abf99776070830 to your computer and use it in GitHub Desktop.
#target photoshop | |
/* Open the given file, and compress with TinyPNG. */ | |
function compressFile(file) { | |
var document = open(file); | |
if (document.mode == DocumentMode.INDEXEDCOLOR) { | |
document.changeMode(ChangeMode.RGB); | |
} | |
var tinypng = new ActionDescriptor(); | |
tinypng.putPath(charIDToTypeID("In "), file); /* Overwrite original! */ | |
var compress = new ActionDescriptor(); | |
compress.putObject(charIDToTypeID("Usng"), charIDToTypeID("tinY"), tinypng); | |
executeAction(charIDToTypeID("Expr"), compress, DialogModes.NO); | |
document.close(SaveOptions.DONOTSAVECHANGES); | |
} | |
/* Recursively compress files in the given folder, overwriting the originals. */ | |
function compressFolder(folder) { | |
var children = folder.getFiles(); | |
for (var i = 0; i < children.length; i++) { | |
var child = children[i]; | |
if (child instanceof Folder) { | |
compressFolder(child); | |
} else { | |
/* Only attempt to compress PNG files. */ | |
if (child.name.slice(-4).toLowerCase() == ".png") { | |
compressFile(child); | |
} | |
} | |
} | |
} | |
try { | |
compressFolder(Folder.selectDialog("Compress folder with TinyPNG")); | |
} catch(error) { | |
alert("Error while processing: " + error); | |
} |
Is it possible to include JPG files in the process? at the moment it seems to affect only PNG files.
If the script runs into an error with opening a file, it stops completely. is it possible to skip the files that give an error?
This script is definitely a life saver!
How do I get it to compress files in subfolders within subfolders? Right now I think it's only looking for files in subfolders and not checking if there are folders within the subfolders.
When I used this script last year it compressed files in subfolders within subfolders. It's no longer doing that. Maybe a change in Photoshop CC 2017 or in the TinyPNG plugin itself? It runs through the files in these subfolders but does not compress them.
Any chance of success to have a JPG compatible version of this please?
Excelente!!! @rolftimmermans
Muchas gracias, funciona muy bien!!! 👍
lo estoy usando en Photoshop 2018 y ya tengo el plugin instalado.
nuevamente muchas gracias.
Excellent!!! @rolftimmermans
Thank you very much, it works very well !!! 👍
I'm using it in Photoshop 2018 and I already have the plugin installed.
again thank you very much.
Thank you so much for this small but great script.
I modified slightly to suit my requirements such as
1)included jpg
'''
if (child.name.slice(-4).toLowerCase() == ".png" || child.name.slice(-4).toLowerCase() == ".jpg") {
'''
2)thks for Otto's modification to escape from termination but I didn't want to stop the process even with an alart window so commented out the alert
3)message window to confirm the process finished
'''
alert("FINISHED");
'''
All worked well with my CS6 , 6000+consecutive files & sub-folders
This is great but it crashes both photoshop 2018 and 2019 when attempting to compress JPEG. Any chances for a updated script?
I just stumbled across tinypng and within 10 minutes found this page. The combination of the two is going to save me HOURS and HOURS. Thank you so much!!