Copy link to clipboard
Copied
I've wrote a script to save multiple file formats out at the desired colour profile. It's still in progress but I've hit a roadblock in the form of not being able to export JPEG files to CMYK or JPEG and PNG to 300dpi. I presumed that because it's actually possible in manual export options that it would've been scriptable, but I cant find anything in the reference and I'm hoping I'm just being ridiculously dumb and have missed a really simple option or adobe have included this feature, as I cant see any recent posts with similar issue. Currently the only work around I can think of is saving a photoshop file and then converting inside of photoshop, but that will require another script and another program and then it will just reduce effectiveness and workflow.
Please can someone help.
Copy link to clipboard
Copied
Sorry but not possible with scripting except with a lot of workarounds. The other thing that might mess everything up is most software expects JPG files to be RGB and 72 ppi. Adobe can read CMYK/300 ppi JPG files but with other software you might get garbage.
Copy link to clipboard
Copied
Options which may be supplied when exporting a document as a JPEG file.
Property | Type | Access | Description |
---|---|---|---|
antiAliasing | bool | r/w | Should the resulting image be antialiased. (default: true) |
artBoardClipping | bool | r/w | Should the resulting image be clipped to the artboard. (default: false) |
blurAmount | number (range: 0.0 - 2.0) | r/w | Blur the resulting image this much. (default: 0) |
horizontalScale | number (range: 0.0 - 776.19) | r/w | Horizontal scaling factor. (default: 100) |
matte | bool | r/w | Should the artboard be matted with a color. (default: true) |
matteColor | RGBColor | r/w | The color to use when matting the artboard (default: white) |
optimization | bool | r/w | Should the image be optimized for web viewing. (default: true) |
qualitySetting | Int32 (range: 0.0 - 100.0) | r/w | Quality of resulting image. (default: 30) |
saveAsHTML | bool | r/w | Should the resulting image be saved as HTML. (default: false) |
verticalScale | number (range: 0.0 - 776.19) | r/w | Vertical scaling factor. (default: 100) |
Copy link to clipboard
Copied
Right Leo, but to get the functional equivalent of 300 ppi you would need to Export at 416.7% and the resave the new file at 24% in photoshop.
Copy link to clipboard
Copied
like this
var resolution = 300;
.
.
.
exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size, resize in PS for a "true" PPI convertion
exportOptions.verticalScale = resolution*100/72;
Copy link to clipboard
Copied
Here is one of the workarounds: the usage of actions in CS6+.
It's not ideal, but it does work. There's the issue of this action only saving the active document under its name in a folder - I do not know how to set a complete file path - but basically you take a recorded save jpg action, paste it and replace the hex-encoded lines in it to put in your own folder path. Then load the action and play it, and then remove it if you so wish.
Or you can just simply have this action not dynamically constructed like this, but always in your palette, and you treat the destination folder as a "hot folder" and make your script grab files from it after they are done being written (may need a sleep loop to wait until file is complete?).
Here's a dynamic-like example, since I'll probably come back to this place to read this again many times
#target illustrator
function test(){
String.prototype.hexEncode = function(){
//http://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex
var hex = '';
for(var i=0;i<this.length;i++) {
hex += ''+this.charCodeAt(i).toString(16);
}
return hex;
};
function writeFile(fileDestStr, contents){
var newFile = File(fileDestStr);
newFile.open('w');
newFile.write(contents);
newFile.close();
};
var actionStr = [
"/version 3",
"/name [ 4",
" 54657374",
"]",
"/isOpen 1",
"/actionCount 1",
"/action-1 {",
" /name [ 12",
" 53617665204d79204a504547",
" ]",
" /keyIndex 0",
" /colorIndex 0",
" /isOpen 1",
" /eventCount 1",
" /event-1 {",
" /useRulersIn1stQuadrant 0",
" /internalName (adobe_exportDocument)",
" /localizedName [ 6",
" 4578706f7274",
" ]",
" /isOpen 0",
" /isOn 1",
" /hasDialog 1",
" /showDialog 0",
" /parameterCount 7",
" /parameter-1 {",
" /key 1885434477",
" /showInPalette 0",
" /type (raw)",
" /value < 104",
" 0a00000001000000030000000200000000002c0102000000000000000100000069006d006100670065006d00610070000000310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000",
// What is the world is this? ^^^ ',imagemap' followed by the remnants of the active file's name? It makes not a lot of sense, anyone know?
" >",
" /size 104",
" }",
" /parameter-2 {",
" /key 1851878757",
" /showInPalette -1",
" /type (ustring)",
" /value [ PUT_FOLDERPATH_CHAR_LENGTH_HERE",
" PUT_HEX_FOLDERPATH_HERE",
" ]",
" }",
" /parameter-3 {",
" /key 1718775156",
" /showInPalette -1",
" /type (ustring)",
" /value [ 16",
" 4a5045472066696c6520666f726d6174",
" ]",
" }",
" /parameter-4 {",
" /key 1702392942",
" /showInPalette -1",
" /type (ustring)",
" /value [ 12",
" 6a70672c6a70652c6a706567",
" ]",
" }",
" /parameter-5 {",
" /key 1936548194",
" /showInPalette -1",
" /type (boolean)",
" /value 0",
" }",
" /parameter-6 {",
" /key 1935764588",
" /showInPalette -1",
" /type (boolean)",
" /value 1",
" }",
" /parameter-7 {",
" /key 1936875886",
" /showInPalette -1",
" /type (ustring)",
" /value [ 1",
" 31",
" ]",
" }",
" }",
"}"
].join("\n");
if(app.documents.length == 0){
return;
}
var dest = Folder.selectDialog("Pick a folder and save the 300ppi CMYK JPEG there.");
if(!dest){
alert("Cancelled");
return;
}
var destStr = decodeURI(dest.fsName);
var actionFileDestStr = Folder.desktop + "/MyAction.aia";
writeFile(actionFileDestStr, actionStr.replace("PUT_FOLDERPATH_CHAR_LENGTH_HERE", destStr.length).replace("PUT_HEX_FOLDERPATH_HERE", destStr.hexEncode()));
var actionFile = File(actionFileDestStr);
app.loadAction(actionFile);
app.doScript("Save My JPEG", "Test");
//clean up
actionFile.remove();
app.unloadAction("Test", ''); // thanks qwertyfly!
};
test();
Copy link to clipboard
Copied
Sorry, my English is not very good. I understand you need to know the path to the file name. If so, absolute.fullName or app.activeDocument.fullName use.
Copy link to clipboard
Copied
It looks like the file name is placed into the section below, but is overwritten partially with ",imagemap".
And, it seems to use active document's current name at export time.
Copy link to clipboard
Copied
Tried to export with filename.
Yesterday, it wen't well.
But today i get an error message
"Illustration could not be saved" -->
"Export as" is currently not available.
Did anyone have this message?
I try again to create the script code.
When i manually create an action with export, it working well.
But my old action with export, its not working. But why?
Copy link to clipboard
Copied
Hi there, thanks for this script! Working well. Only thing that i couldn't setup, is the filename for export.
But now, i found a solution.
---
I first suspected, the hex value in parameter 1 is responsible for setting the filename.
But after decrypting, i get only half of the filename, i originally saved.
---
Saved an action for export JPG with filename 123456789_ABCDEFGHIJK.jpg
-->
Parameter 1:
/value < 104
0a00000001000000030000000300000000002c01020000000000000001000000 // ,
69006d006100670065006d006100700000005f00410042004300440045004600 // imagemap_ABCDEF
4700480049004a004b0000000000000000000000000000000000000000000000 // GHIJK
0000000000000000
>
/size 104
---
Then i found the filename in Parameter 2, that first as suspected, is responsible for export folder.
Parameter 2:
/value [ 59
433a5c55736572735c4b6576696e5c4465736b746f705c4578706f72745c4a50 // C:\Users\Kevin\Desktop\Export\JP
475c3132333435363738395f4142434445464748494a4b2e6a7067 // G\123456789_ABCDEFGHIJK.jpg
]
---
So i changed the code, so that i include the filename in line 120:
instead of var destStr = decodeURI(dest.fsName);
Now working well.
Copy link to clipboard
Copied
Here is a sample solution of export PNG:
function exportPNG(pth){
var str = "";
for (var i=0;i<pth.length;i++) str += u16to8(pth.charCodeAt(i));
var act = "/version 3"
+ "/name [ 4 73657431]"
+ "/isOpen 1/actionCount 1"
+ "/action-1 {/name [ 7 616374696f6e31]"
+ "/keyIndex 0/colorIndex 0/isOpen 1/eventCount 1"
+ "/event-1 {"
+ "/useRulersIn1stQuadrant 0"
+ "/internalName (adobe_exportDocument)"
+ "/isOpen 0/isOn 1/hasDialog 1/showDialog 0"
+ "/parameterCount 6"
+ "/parameter-1 {/key 1851878757/showInPalette 4294967295"
+ "/type (ustring)"
+ "/value [ " + str.length/2 + " " + str + "]}"//Fullpath of the target file in UTF-8 Hexadecimal
+ "/parameter-2 {/key 1718775156/showInPalette 4294967295"
+ "/type (ustring)"
+ "/value [ 16 41646f626520504e4720466f726d6174]}"
+ "/parameter-3 {/key 1702392942/showInPalette 4294967295"
+ "/type (ustring)/value [ 3 706e67]}"
+ "/parameter-4 {/key 1936548194/showInPalette 4294967295/type (boolean)/value 0}"
+ "/parameter-5 {/key 1935764588"
+ "/showInPalette 4294967295/type (boolean)/value 1}"
+ "/parameter-6 {/key 1936875886/showInPalette 4294967295/type (ustring)/value [ 0]}}}"
var tmp = File(Folder.desktop + "/tmpSet1.aia");
tmp.open('w');
tmp.write(act);
tmp.close();
app.loadAction(tmp);
app.doScript("action1", "set1", false);
app.unloadAction("set1","");
tmp.remove();
}
function u16to8(cd) {
var out =
(cd < 0x80
? toHex2(cd)
: (cd < 0x800
? toHex2(cd >> 6 & 0x1f | 0xc0)
: toHex2(cd >> 12 | 0xe0) +
toHex2(cd >> 6 & 0x3f | 0x80)
) + toHex2(cd & 0x3f | 0x80)
);
return out;
}
function toHex2(num) {
var out = '0' + num.toString(16);
return out.slice(-2);
}
var pth = Folder.selectDialog("target Folder?").fsName + "/test.png";
exportPNG(pth);
We have to write string codes of File and Folder names in UTF-8.