-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path[IG]_Save_For_Web.jsx
85 lines (71 loc) · 2.8 KB
/
[IG]_Save_For_Web.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// **************************** Photoshop Script *************************//
// ***********************************************************************//
//
// ** [IG]_Save_For_Web
// ** @description Save for web portion of document what is selected with
// marquee tool. Before it will be saved the trim operation
// will be applied to transparent pixels. If no selection
// then entire document will be saved.
// **
// ** @author Igor Grinchesku <igor.grinchesku@gmail.com>
// ** @github https://github.com/Arahnoid/IG-Photoshop-Scripts
// ** @date August 6, 2014
// ** @require Adobe Photoshop CS5, or higher
// ** @instalation https://github.com/Arahnoid/IG-Photoshop-Scripts
//
// ***********************************************************************//
// BEGIN__HARVEST_EXCEPTION_ZSTRING
<javascriptresource>
<name>$$$/JavaScripts/[IG]_Save_For_Web/Menu=[IG] Save For Web</name>
<category>IG</category>
<enableinfo>true</enableinfo>
<eventid>b15f842c-c855-4bc8-a4c5-288c097dc082</eventid>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRING
#target photoshop
app.bringToFront();
// ********************************** START ******************************//
if (app.documents.length) { // Document exists
var doc = app.activeDocument;
try { // Selection exists
var bounds = app.activeDocument.selection.bounds;
// Get with and height of image
var xtop = bounds[0],
ytop = bounds[1],
xbot = bounds[2],
ybot = bounds[3],
nDocWidth = xbot - xtop,
nDocHeigh = ybot - ytop;
// Create new document
var tempDoc = app.documents.add(
nDocWidth,
nDocHeigh,
72,
'TempDoc',
tempDocumentMode.RGB,
DocumentFill.TRANSPARENT);
// Paste image from clipboard into new document
tempDoc.paste();
// Trim transparent pixels
tempDoc.trim(TrimType.TRANSPARENT, true, true, true, true);
// Display dialog windows
displayDialogs = DialogModes.ALL;
// Create default file object and open save for web dialog
WEBFile = new File('file');
app.activeDocument.exportDocument(WEBFile, ExportType.SAVEFORWEB);
app.displayDialogs = DialogModes.NO; // Hide dialog windows
// Close Temp document without saving
tempDoc.close(SaveOptions.DONOTSAVECHANGES);
} catch (e) { // No selection
displayDialogs = DialogModes.ALL; // Display dialog windows
// Create default file object and open save for web dialog
WEBFile = new File('file');
app.activeDocument.exportDocument(WEBFile, ExportType.SAVEFORWEB);
app.displayDialogs = DialogModes.NO; // Hide dialog windows
// Close Temp document without saving
tempDoc.close(SaveOptions.DONOTSAVECHANGES);
}
} else { // No document
alert('No opened document to work with.');
}
//** End of script ====================================================== **//