Copy link to clipboard
Copied
For example, I have a jpg file for my IconButton, I know how to access the image via specifying its file path. But how can I embed it into my script so that I don't need it on my disk while my script works fine ?
The principle is to insert the image file binary into the script file.
In an auxiliary script, you can do:
var myFile = new File(myImageFileURI);
var myBin;
myFile.encoding="BINARY";
myFile.open();
myBin = myFile.read().replace("(new String(", "").replace(/\)\)$/, ""); // strip off (new String(...))
Then the string myBin is what you can use in your main script as image data instead of a file, that is, you can do:
var myIcon = ScriptUI.newImage(myBin);
See this very useful pdf fore more details: ScriptUI for dummies | Peter Kahrel
...Copy link to clipboard
Copied
Hi Aaron.
There's a script that handles this stuff for you Export to Bytes - aescripts + aeplugins - aescripts.com
Follow the onscreen instructions and you should be able to get what you need.
Cheers.
Copy link to clipboard
Copied
Thanks, Tomas. I've found the similar way.
Copy link to clipboard
Copied
The principle is to insert the image file binary into the script file.
In an auxiliary script, you can do:
var myFile = new File(myImageFileURI);
var myBin;
myFile.encoding="BINARY";
myFile.open();
myBin = myFile.read().replace("(new String(", "").replace(/\)\)$/, ""); // strip off (new String(...))
Then the string myBin is what you can use in your main script as image data instead of a file, that is, you can do:
var myIcon = ScriptUI.newImage(myBin);
See this very useful pdf fore more details: ScriptUI for dummies | Peter Kahrel (embedded images are towards the end in an appendix).
There is one drawback with graphics embedded as binaries: they won't update.
For instance, if you create an icon button with four states:
var myIconButton = myGroup.add("iconbutton);
myIconButton.image = ScriptUI.newImage(myBin1, myBin2, myBin3, myBin4);
The iconbutton wont update its graphics upon mouseover/mousedown etc.
(If you use file data instead of binaries it works fine, so even if you embed binaries, you might have to re-deploy the icon data as files to make it work).
Xavier
Copy link to clipboard
Copied
If you need a more in depth explanation, I also show how to do this in my advanced scripting course at fxphd (class 3)
https://www.fxphd.com/blog/new-course-advanced-scripting-for-after-effects/
(not free)
Copy link to clipboard
Copied
Thx. Definitely I will check this out later when I come back from my new year festival!
Copy link to clipboard
Copied
Thanks,Xavier. But I still got problem with this. My code is as following:
var myFile = new File("~/Desktop/1.jpg");
var myBin;
myFile.encoding="BINARY";
myFile.open("r");
myBin = myFile.read().replace("(new String(", "").replace(/\)\)$/, "");
myPanel.grp.icon.image = myBin;
But after I delete my image from my desktop, ESTK tells me that "File or folder does not exist" everytime I relaunch my script. Any way to fix this?
Copy link to clipboard
Copied
Hey, Xavier. You can ignore my last reply to you, cause I've found the way in the pdf file you've mentioned.
I convert the image to binary data, strip off the unnecessary parts, and write it into a txt file. Then copy and paste the content of the txt file into my script. It works really well. Thanks for your help!