How to Create Binary data for my Image inside My Script

Enthusiast ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Hi Experts,

I Wish to know if possible to include the image data as binary inside my script instead just showing my image inside the script, for now i use the following :

//Script Path with Image
var scriptFile = new File($.fileName);
var scriptPath = scriptFile.parent.fsName;

var w = new Window ("dialog", "Testing");
var pics = w.add ("image", undefined, File (scriptPath+"/MyScriptName_.png"));
w.show ();

and the Result is this :

My Script Name v3.jpg

but this mean i have to distribute the Script + Image file (Png) in my case, and i think this is frustrating! and may cause errors if some one forget to copy the image within script folder (in same place), So Can i convert image into binary data and use it inside my script? and How? and thanks in Advance.

 

Best
M.Hasanain
TOPICS
Scripting

Views

131

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 , Dec 11, 2021 Dec 11, 2021

Hi @M.Hasanain, check out page 115 of Peter Kahrel's book on ScriptUI.

- Mark

Likes

Translate

Translate
Adobe Community Professional ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

Hi @M.Hasanain, check out page 115 of Peter Kahrel's book on ScriptUI.

- Mark

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 ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

LATEST

Thanks @m1b alot

I read it and Succesfully Convert my Image to Binary,, My Modified Script is :

//Script Path with Image
var scriptFile = new File($.fileName);
var scriptPath = scriptFile.parent.fsName;

//Convert the contents of the binary file to a string
var infile = File (scriptPath+"/MyScriptName_.png");
var outfile = File (scriptPath+"/MyScriptName.txt");
infile.open ("r");
infile.encoding = "binary";
var temp = infile.read();
infile.close();
outfile.open ("w");
outfile.write (temp.toSource ());
outfile.close ();
Best
M.Hasanain

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