-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresizeMyImages.jsx
executable file
·57 lines (48 loc) · 1.38 KB
/
resizeMyImages.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Resizer script
*
* Copyright (c) Mohammad Jangda ([email protected])
*
*/
#target photoshop
const MAX_WIDTH = 640;
const MAX_HEIGHT = 480;
resizeMyImages();
function resizeMyImages() {
var docs = app.documents;
var count = docs.length;
var maxWidth = new UnitValue (640, "px");
var maxHeight = new UnitValue (480, "px");
for (var i = 0; i < count; i++) {
doc = docs[i];
fname = doc.name;
fname = File(doc.path + "/" + fname);
app.activeDocument = doc;
if (doc.width.as("px") < maxWidth.as("px") && doc.height.as("px") < maxHeight.as("px")) {
// alert("no resize needed");
} else {
if (doc.width.as("px") > doc.height.as("px")) {
doc.resizeImage(maxWidth);
} else {
ratio = doc.width.as("px") / doc.height.as("px");
// alert(ratio);
width = maxHeight * ratio;
doc.resizeImage(width,maxHeight);
}
}
//ensure RGB mode
if(doc.mode!="RGB") {
doc.changeMode(ChangeMode.RGB);
}
// Save as JPEG
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 8;
app.activeDocument.saveAs(fname, jpgSaveOptions, false, Extension.LOWERCASE);
}
//Close all open images
while (app.documents.length) {
app.activeDocument.close();
}
}