Guest User

Untitled

a guest
May 5th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #target photoshop
  2.  
  3. /* Open the given file, and compress with TinyPNG. */
  4. function compressFile(file) {
  5. var document = open(file);
  6.  
  7. if (document.mode == DocumentMode.INDEXEDCOLOR) {
  8. document.changeMode(ChangeMode.RGB);
  9. }
  10.  
  11. var tinypng = new ActionDescriptor();
  12. tinypng.putPath(charIDToTypeID("In "), file); /* Overwrite original! */
  13.  
  14. var compress = new ActionDescriptor();
  15. compress.putObject(charIDToTypeID("Usng"), charIDToTypeID("tinY"), tinypng);
  16. executeAction(charIDToTypeID("Expr"), compress, DialogModes.NO);
  17.  
  18. document.close(SaveOptions.DONOTSAVECHANGES);
  19. }
  20.  
  21. /* Recursively compress files in the given folder, overwriting the originals. */
  22. function compressFolder(folder) {
  23. var children = folder.getFiles();
  24. for (var i = 0; i < children.length; i++) {
  25. var child = children[i];
  26. if (child instanceof Folder) {
  27. compressFolder(child);
  28. } else {
  29. /* Only attempt to compress PNG files. */
  30. if (child.name.slice(-4).toLowerCase() == ".png") {
  31. compressFile(child);
  32. }
  33. }
  34. }
  35. }
  36.  
  37. try {
  38. compressFolder(Folder.selectDialog("Compress folder with TinyPNG"));
  39. } catch(error) {
  40. alert("Error while processing: " + error);
  41. }
Add Comment
Please, Sign In to add comment