Export JPG as 300 ppi?

Engaged ,
Jun 26, 2020 Jun 26, 2020

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:

  1. When I use app.activeDocument.exportFile, it produces a smaller image or blurry output compared to what the client wants. I need it to result in 300 ppi but it only produces 72 ppi.
  2. When I use app.activeDocument.imageCapture instead, it appears to be perfect and it doesn't say anywhere that it only supports PNG, but when I export JPG from this and try to place the results in Illustrator, it claims that they're unsupported files and Illustrator doesn't know how to open them. So it appears I'm creating corrupted PNGs which have been renamed as ".jpg" instead of actual JPG images.
TOPICS
Scripting

Views

842

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Jun 26, 2020 Jun 26, 2020
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 ...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 26, 2020 Jun 26, 2020

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.

 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 26, 2020 Jun 26, 2020

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.

https://community.adobe.com/t5/illustrator/eps-to-jpg-export-options-in-300-dpi-illustrator/td-p/957...

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2020 Jun 26, 2020

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).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 27, 2020 Jun 27, 2020

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:

ice_screenshot_20200627-075124.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

Please excuse the obvious question, but why not export as TIF?  ExportOptionsTIFF has a "resolution" property. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

Not my choice unfortunately, I've been given a requirement for 300 dpi JPG, bulk export from the app.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 27, 2020 Jun 27, 2020

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 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

Looks really promising! Thanks as always Carlos.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

my pleasure Tom.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 25, 2021 May 25, 2021

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?!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

what do you mean by "get document size for the export"?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 25, 2021 May 25, 2021

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

Export for screen dialogExport for screen dialog

 

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 si the error dialog im getting when scale is to bigThis si the error dialog im getting when scale is to big

 

 

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. 
Logo packer panelLogo packer panel
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.
Original panelOriginal panel

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

LATEST

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.

Export testsExport tests

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines