Copy link to clipboard
Copied
Hi guys, I have an issue where I need to batch export JPGs from files saved as 72 ppi, but the result needs to be 300 ppi. I don't see a way to set this via ExportType.JPEG and ExportOptionsJPEG, and I don't see a way to get the current PPI of Illustrator in order to know how much to scale the image to match.
My issues are:
Hi,
Could you please try using actions
var dest = Folder(Folder.desktop);
function main() {
String.prototype.hexEncode = function () {
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
...
Copy link to clipboard
Copied
Hi,
Could you please try using actions
var dest = Folder(Folder.desktop);
function main() {
String.prototype.hexEncode = function () {
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 [ 9",
"4578706f7274204173",
"]",
"/isOpen 1",
"/isOn 1",
"/hasDialog 1",
"/showDialog 0",
"/parameterCount 7",
"/parameter-1 {",
"/key 1885434477",
"/showInPalette 0",
"/type (raw)",
"/value < 104",
"0a00000001000000030000000200000000002c0101000000000000000100000069006d006100670065006d00610070000000310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
">",
"/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 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", '');
};
main();
I have got this a long ago from old thread only. May be it works for you too.
Copy link to clipboard
Copied
Found the reference link for the above answer. Credit goes to person for below link - Its says EPS to JPEG.
Copy link to clipboard
Copied
There is no "current ppi" in Illustrator because it is a vector app. There is no ppi at all (except an unrelated value for raster effects).
Copy link to clipboard
Copied
That might be technically true but the issue still stands that you export JPG via scripting by default in 72 ppi but I need to export in 300, and this is an available setting within File > Export As that I can't find a scripting solution for other than what Charu shows for loading an action:
Copy link to clipboard
Copied
Please excuse the obvious question, but why not export as TIF? ExportOptionsTIFF has a "resolution" property.
Copy link to clipboard
Copied
Not my choice unfortunately, I've been given a requirement for 300 dpi JPG, bulk export from the app.
Copy link to clipboard
Copied
besides using actions, the only way to export to 300 was to scale the artwork. Bigger artwork gave us more pixels. The file was still 72 ppi but it gave us decent results mimicking higher resolution.
that was until Export For Screens was introduced a couple of versions ago.
here is a sample showing both options. Select something before running the script
// export selection by Resolution
// carlos canto - 06/27/2020
// https://community.adobe.com/t5/illustrator/export-jpg-as-300-ppi/td-p/11244200?cid=101&cgid=18269&page=1
function main() {
var idoc = app.activeDocument;
var asset = idoc.assets.addFromSelection();
asset.assetName = 'myExportedAsset';
var destFolder = Folder('~/desktop');
var resolution = 300;
exportItem (asset, destFolder, resolution);
var destPath = destFolder + '/mySaveAsFile.jpg';
exportFileToJPEG (destPath, resolution);
}
function exportItem(item, destFolder, resolution) {
// turn create folders off, same as unchecking the setting on the UI Export Assets window
app.preferences.setIntegerPreference ('plugin/SmartExportUI/CreateFoldersPreference', 0); // don't create subfolders
var whatToExport = new ExportForScreensItemToExport();
whatToExport.assets = [item.assetID];
whatToExport.artboards = ''; // don't export artboard
whatToExport.document = false; // don't export document
var jpgOptions = new ExportForScreensOptionsJPEG;
jpgOptions.antiAliasing = AntiAliasingMethod.TYPEOPTIMIZED; // art optimized results in jagged edges, is it a bug?
jpgOptions.compressionMethod = JPEGCompressionMethodType.BASELINEOPTIMIZED; // BASELINESTANDARD
jpgOptions.scaleType = ExportForScreensScaleType.SCALEBYRESOLUTION;
jpgOptions.scaleTypeValue = resolution;
activeDocument.exportForScreens (destFolder, ExportForScreensType.SE_JPEG100, jpgOptions, whatToExport);
}
main();
function exportFileToJPEG (dest, resolution) {
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest);
exportOptions.antiAliasing = true;
exportOptions.artBoardClipping = false;
exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size,
exportOptions.verticalScale = resolution*100/72;
exportOptions.qualitySetting = 100;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
Carlos
Copy link to clipboard
Copied
Looks really promising! Thanks as always Carlos.
Copy link to clipboard
Copied
my pleasure Tom.
Copy link to clipboard
Copied
HI carlos, do you know a method to get document size for the export. I cant seem to find this in any docs. None of the scripting references contain any info about exportforscreensoptiosn 😞
You scaling method works till it bumps into a scale limit of 777 for jpg. all the other formats scale just fine?!
Copy link to clipboard
Copied
what do you mean by "get document size for the export"?
Copy link to clipboard
Copied
oh, I see what you need.
instead of scaling by resolution
jpgOptions.scaleType = ExportForScreensScaleType.SCALEBYRESOLUTION;
jpgOptions.scaleTypeValue = resolution;
you need to scale by Width or by Height
jpgOptions.scaleType = ExportForScreensScaleType.SCALEBYWIDTH;
jpgOptions.scaleTypeValue = YOUR_DESIRED_WIDTH;
Copy link to clipboard
Copied
Thanks for the reply Carlos, also in the other thread.
I have already tried that method and i bump into a limit. I find this weird, because with the Export for screens dialog it does work. I think the width in that panel is the same as SCALEBYWIDTH right? see screengrab
The "issue" i have is that im making a logo packer panel, at least ive been doing upgrades to an existing one, adding more features and customizing it. The original exported the files at the original docs size, which was horrible. In my test file, the logo mark is around 27x27 pixels. When i used my script to get it to 1000px or testing it with hard-coded values, the max goes up to 500 something. When i open a doc its 500x500px that is using SCALEBYRESOLUTION. When i try to use SCALEBYWIDTH the max is around 777 or so. When i use hard-coded 1000 is throws this error again it cant export. Yet the other formats, png, ai and pdf work just fine using that same approach. Though AI and PDF use the saveas function.
This is the panel im updating. For me as a graphic design this is so handy, takes a 1-2 hour job and does it with seconds. It exports all files to there own folder with proper naming like digital, print, cmyk or rgb, also adds logo, logomark, logotype or slogan. Users can each use the current selection or drag and drop the active selection onto the panel. I also added easy open export folder and clean eport folder functions. Also added the github page and issue page so users can easily report bugs or other issues they find.
This is how the oroginal panel looks. Hope the dev doesnt mind me adjust it a bit. Ive posted on his github, but no response yet.
Copy link to clipboard
Copied
maybe scalebyWidth also abides to the 777 scale limit.
all I can think of is, if you need to go beyond 777, try scaling the Logo first then try exporting.
Copy link to clipboard
Copied
I noticed the bigger formats of the logo do export. Also the SCALEBYWIDTH does exactly do what i need, i wasnt using it properly. I used a scale method calculated from the basewidth and did some math to get a scale value. I just need to hardcode say 1000px.
What i now see is that the minimal input it takes is a logo of 70pt wide. everything below that will fail. This is weird because if i use the dialog, the scale width method does work?!?
Though i need to think of a clean method to do this. I think i would need to make a function which only upscale the actual shapes/objects for the JPG version. Then after the export it deletes all of these. I do this because normally a logo i setup in a scale so it can be used easy for designing items. So i set a scale usefull for print items like business cards and letterheads. That way its easier when they are placed inside Indesign. You wont get a HUGE logo there.
I think i would need to clean those items because perhaps users would like to save this sheet with all logo versions. I need to think about it. Perhaps ill make it an options or so.