Silly-V / Adobe-Illustrator

Some useful Adobe Illustrator scripts
418 stars 298 forks source link

Question about embeded images #44

Closed schroef closed 3 years ago

schroef commented 3 years ago

Hi Silly,

Your scripts are so cool to look at. Really way above my capabilities, but i look to scroll through them and see if i can learn from it. I noticed in a couple scripts you have different methods of embedding images. I was looking for something like this. I knew i saw used a couple times and only could remember 2 of you scipts or panels having.

What is the coding or desiphering for this, not sure how its called. I thought something like Binary or Hex. I noticed some parts still have readable text and was quite funny seeing them made with old app ImageReady

this is the code i mean


        img_logo2 : ScriptUI.newImage("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00d\x00\x00\x00-\b\x02\x00\x00\x00\u00D7\u00D7Y\u00A7"+
        "\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\u00C9e<\x00\x00\x03\u00F3IDATx\u00DA\u00EC[\u00E9\u0091\u00EA0\fvv\u00A9\u00826"+
        "\u00A0\u00A6P\x07e@\x1D\u0094\x01uPF\u009E\x06\r\x1A\u00AD$\u00CB\u00B2\u009Dpd\u009E~\u00EC\u0090\u00C4\u0087\u00A2\u00DB\u009F"+
        "\u00B2\u00C34M\u00A9\u009En\u00B7\x1B\u00FC=\u009F\u00CFt\x07\x7F\u008F\u00E3\u00C8\u00EF\u00E3\u00A5\x1Es:\u009D\u00D2\x17\u00D2"+
        "\u00D0,,\u0092\b\x17\u00D9\u00F5z\u00DD\u00EDv(\u00CA\u00FD~/\x16\u00C7\u00FB@0f\u00B5\u00C2\x12v\u00C4\u00A5\u00A3\t\r\x07\u00A6|"+
        "\u00A9D\x1C\u00DAD\u00CC\u00C7\u0097\u008E .S4\u00B4\u0095\x0B\u00EBp8T\t\u00C8\u00B4\u00AF\u00B4>\u009A\x145\u00BF'L\u00BC>"+
        "\b~Lo%\u00E0a\u0089e\u0093\u00DE\u00A6MF\x7F\x16}D\u00FAwI\n\u0095\u00BD\x04\x03?\u00E2\u00CD!\u0085\u00D5\u008A\t\u00C29\x0FL"+
        "\u0094\u00F2\x1C\x027\x1F\u009Etx\u00D0\u00DB=\f\u00D8\x066\n\u00CC7\u0098\u00956%\u009A\u008E>\u00E8\u00BB!j~|R.\x1A\u00F4"+
        "\u00F8`\u0083Y\u00E1\u00BB\u00FB\x13\u0093p\u009F\u0088\u00A4\u00CC\u009Dx\u00A4s\u00B6D\u009E\u00F8\"8Q\u00AF\u0086\u0084"+
        "\u00BFqA\u00BAo^\u00EA\u0089zA\u00AEN\u00C1d\u009D\u00B0\u00E2f\u0095\u0093QQR\u00A6\u00B0DB\u00A0\x05\u00F9\u00CA8 \u00C7!M"+
        "\u00E7\x03\u0084\u00B0\u009C\u0089\u00B9\u00A7\u00FAERm\x12$m\u00C7\u00DDSn\u00F9\x1C\u00AC5,b3\u00BD\x06\x1FF[\u0093}\x15m"+
        "\u00843L\u00B3\u00C4%\x05\u0087+\u00A3^aUE\u00B1\u009Cq\u0089\u0080E\u00A6\u00E1\u0084Q!\u00AC\u00A2\u00A7\u008B\x01$\u008B"+
        "\u009C\u008DG\u00DCp3K*\u0081-\u0083\u0095:\u009E\n\u00E8 \r\x13\u00CF\x0F\u00A2\x15\u0084\u00CE\u00E0&p)\u0092T|;\u00A7TnY\u00A1"+
        "\u00A7\u00C2\u008A\u0087*\u00A7\b\u00E2*5\u009F\u008A\u0094R\u00CC\u00B6\u00A6\x1B\u009A\x01W[\u0096\u00BFr\u009A\u00A5v\u008F"+
        "\u00CB\u008B\u00BB\x1E\u00C6\u0085\\(1\x03\u008D\x18 $\u00C2g\u00D1\u00FAf\u00F8\u00D3\u00DE\u008DA\u0080\"\u00B2\u00E9\u00EC"+
        "\u00C9\u008C\u00BE3\x1E\u009E\"'\x04?s\u0091\u00B6M]\x165\u00CD\u00D5 \u00C6\u0098q\u008D\u00E7\x1F1`\u00D0\u0090SU\x11o2\u00E7"+
        "\u0084\x03\u008CY\u00C0\x07\u00EE\u0082<\u0089\u00F1\u0084v \u00F7\u00F4\u00D4,\u00AF\u00FD\u00A74\x06\u00DFKhB\u00F3\u0089"+
        "\u008Bd\u00F9\x0F*\x7F\u0089\u00F8\u00F5\u00E2\u00A3u?c\u00C9\u008F,\u00EB\u0090\u0097P\x7F3(b\u0097\x0E\u0098\u00DA{ -\u00B0"+
        "\u00F9\u008F\u00C2\u00DAE<\u009A3$\u00F7{b\u00A7\x0E?\u0093R\u00CE\u0099E\u0091\u00DDV\u00D3\x7Ff\u00FC\u00EA\u008AY~"+
        "\u0099\u00D7fe<a\u00AFF^\u00A9!@V\u009D\x13\u008B\x05\u00F7\u0097\u00B9a\u00FC\u00F4\u00DB\u0090\x04\u00D7d\\CU\u00CE2"+
        "\u00BB>t\u00BC\u00C8\u00D5r\u0088\x1A\u00BF=3r\u00F0\u00BA\u008D\u0099MC\x02Fy\u00A1\u00C9D\u00CE\u00EEX\u00AF#\x7F&\u00DC"+
        "\u00DE\u008C\"4\x102\u00DF\u00AE\u00B9Z\x1F\x11\u00E7\u00DB\u0090\u00B7?k\u0094\\\u00BD\u00F32?\u00D5(\u00F6Rn(\u008E\u0090"+
        "\u00F1\u00B9`P4\u0092\u008EihMb)\u00FE\x15\u00850:\u00F1H\u009B\u00A43WD\u0092F\u00C8\u00A0!U\u00F1`\x1F\u009C\u00AE\u0081$"+
        "\u008D\u008D\u00E40x\r(\u009BO9\b\u00E3\u00B0\u00D7cY\u00D5m(\x01\fE\x00e\x01\u00E0\t\fD\u0083p\u00E2\u00FD\u00F5\\\x1A\u00A0"+
        "\u00A5\u00EC \u00FA3\b+nYf\u00BF+\u00D2\u00AC7\u00BB\x12\u00B9\u00B8\u00E9\u00E0Yf\x1BM\u00E0\u00F7##\u00D3\u00B8z\u0084"+
        "\u00B5\u00E1\u00F8w1H\u00E9p\x00\x7F\u009D\x15\b\u00BD\u00D2O\u00F9\u00CB\u00F0\u00A8\u0084\u00BB\u00A0\\\x10\u009EoF\u00CD"+
        "\u00A9\u00A6\u0099\u00F9D\u00EE7rs\u00DA\u00E6}\u009A\u009C%\u009A}\u00AA\\\u00FA#\u00C7\x11\u00F0f\u00EE<\u00A0-k\u00D1l\x18"+
        "\x12VQ9BXN\x13?\u0087\u0091;!\u009C\u00B7\u00A0\u009D\u00DE\u009Fn\u00FC\u0089\u00F6\x17\u00BF\u0099\u00EB\fF:\u009E\u00E56\\U"+
        "\u0097\u00C8\u0089\u00FA\u00BE\u0094\x1D\u00AD\u0088D\u00A9/\u00CD\u00E9Z\u00D0=5\u00E6  zl\u00EA\u00F1\u008F\x1C\u0083\u00A8"+
        "<\n\x02\u00AB\x18\x07\u0086\u00D7H\u00B9\x06\u00E0\x1D\x1C\u00DD\u00B94\u00A7\x17?\u00EF\u00E9:9\u0090\x1Ej!fn\u00E1\u00D3J\u00A9"+
        "\\\u00A3V\u00E13+\u0096\x14\u00D0\u00AFv\u0093\u00E3\u00F1x\u00BF\u00DF/\u0097\u00CBv\u00BB\u0085\x1F\u00F1O\u00D4V\u00F6\u00B9"+
        "\u00AD\u00A6a\u00AE\u0085V/)\u00A0\u00DF\x19\u00D7Bc\x04J\u00FFi\u00A1/\u0090\u00BE\t)}e\u00C3\x0EO0\u00DF\u00FB\u00BF;\u00FF\x04"+
        "\x18\x00\u008E\x12\u00A4D\u00A8xh\u00C0\x00\x00\x00\x00IEND\u00AEB`\u0082")
    };```
schroef commented 3 years ago

Doing a google with the first couple characters and it was indeed a BinaryString. Now i wonder what you used to create this. I vaguely remember using this before but cant remember what i used back then :(

Silly-V commented 3 years ago

I dug around, here's the function I used to turn an image into string: `#target illustrator

targetengine main

function test(){ var chosenFile = File.openDialog("Choose file"); if(chosenFile == null){ return; } var infile = File(chosenFile.fsName.replace('file://', '')); infile.open ("r"); infile.encoding = "binary"; var temp = infile.read(); infile.close();

var encodedImageData = temp.toSource().replace('(new String("', "").replace('"))', ""); var encodedImageDataURI = encodeURI(temp);

var w = new Window("dialog", "Image Data"); w.margins = [4,4,4,4]; w.spacing = 4; var g0 = w.add("tabbedpanel"); g0.spacing = 2;

var t1 = g0.add("tab", undefined, "Encoded"); var disp_imageData = t1.add("edittext", undefined, encodedImageData, {multiline : true}); disp_imageData.size = [400, 400];

var t2 = g0.add("tab", undefined, "URI Encoded"); var disp_imageDataURI = t2.add("edittext", undefined, encodedImageDataURI, {multiline : true}); disp_imageDataURI.size = [400, 400];

var t3 = g0.add("tab", undefined, "How well the image shows up"); try { var uiImg = ScriptUI.newImage(decodeURI(encodedImageDataURI)); t3.add("image", undefined, uiImg); } catch(e){ t3.add("statictext", undefined, "Sorry, this image data could not be made into ScriptUI newImage() for some reason.", {multiline : true}); }

var g_btn = w.add("group"); var btn_ok = g_btn.add("button", undefined, "Oookay"); // w.defaultElement = btn_ok; // caused crash - had to switch to Window.close event. btn_ok.size = [400, 26];

btn_ok.onClick = function(){ w.close(); }

w.show(); } test();`