8 Replies Latest reply on Feb 16, 2016 8:33 AM by Silly-V

    Export jpeg and png24 to CMYK 300dpi

    Sc0lie

      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.

        • 1. Re: Export jpeg and png24 to CMYK 300dpi
          Larry G. Schneider Adobe Community Professional & MVP

          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.

          • 2. Re: Export jpeg and png24 to CMYK 300dpi
            LeoMari Level 2

            Class

            ExportOptionsJPEG

            Options which may be supplied when exporting a document as a JPEG file.

            Class

            PropertyTypeAccessDescription
            antiAliasingboolr/wShould the resulting image be antialiased. (default: true)
            artBoardClippingboolr/wShould the resulting image be clipped to the artboard. (default: false)
            blurAmountnumber (range: 0.0 - 2.0)r/wBlur the resulting image this much. (default: 0)
            horizontalScalenumber (range: 0.0 - 776.19)r/wHorizontal scaling factor. (default: 100)
            matteboolr/wShould the artboard be matted with a color. (default: true)
            matteColorRGBColorr/wThe color to use when matting the artboard (default: white)
            optimizationboolr/wShould the image be optimized for web viewing. (default: true)
            qualitySettingInt32 (range: 0.0 - 100.0)r/wQuality of resulting image. (default: 30)
            saveAsHTMLboolr/wShould the resulting image be saved as HTML. (default: false)
            verticalScalenumber (range: 0.0 - 776.19)r/wVertical scaling factor. (default: 100)
            • 3. Re: Export jpeg and png24 to CMYK 300dpi
              Larry G. Schneider Adobe Community Professional & MVP

              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.

              • 4. Re: Export jpeg and png24 to CMYK 300dpi
                CarlosCanto Adobe Community Professional & MVP

                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;
                
                • 5. Re: Export jpeg and png24 to CMYK 300dpi
                  Silly-V Adobe Community Professional

                  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();
                  
                  • 6. Re: Export jpeg and png24 to CMYK 300dpi
                    Ten A Adobe Community Professional

                    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.

                    • 7. Re: Export jpeg and png24 to CMYK 300dpi
                      LeoMari Level 2

                      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.

                      • 8. Re: Export jpeg and png24 to CMYK 300dpi
                        Silly-V Adobe Community Professional

                        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.