• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to embed an image into my ExtendScript?

Explorer ,
Jan 19, 2017 Jan 19, 2017

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 ?

TOPICS
Scripting

Views

5.5K

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

Advocate , Jan 20, 2017 Jan 20, 2017

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

...

Votes

Translate

Translate
Advocate ,
Jan 20, 2017 Jan 20, 2017

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.

Votes

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
Explorer ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Thanks, Tomas. I've found the similar way.

Votes

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
Advocate ,
Jan 20, 2017 Jan 20, 2017

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

Votes

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
Community Expert ,
Jan 20, 2017 Jan 20, 2017

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)

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

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
Explorer ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Thx. Definitely I will check this out later when I come back from my new year festival!

Votes

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
Explorer ,
Jan 20, 2017 Jan 20, 2017

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?

Votes

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
Explorer ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

LATEST

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!

Votes

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