Packing/Concealing external resources

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

undavide

Packing/Concealing external resources

Post by undavide »

Hello,
for a project of mine (which is going to be released as a paid script) I need several images to be dynamically loaded by the ScriptUI GUI. So far I've simply stored these jpgs/png in a separate folder that I access directly but I'd like to hide/pack these resources so that they're not accessible (i.e. the user cannot grab them).

I know that I can stringify images by means of functions such as the following one by Peter Karhel:

Code: Select allfunction graphic_to_text(infiles /*array of file objects*/ ) {
   var outfile, s,
      re1 = /^\(new String\(/,
      re2 = /\)\)$/;
   for (var i = 0; i < infiles.length; i++) {
      if (infiles.exists) {
         outfile = File(infiles.fullName.replace(/\.(png|idrc|jpg)$/, ".txt"));
         infiles.open("r");
         infiles.encoding = "BINARY";
         outfile.open("w");
         s = infiles.read();
         outfile.write(s.toSource().replace(re1, "").replace(re2, ";"));
         infiles.close();
         outfile.close();
      }
   }
}

and embed them in the JSX, but I'd need around 30-60 jpgs and I'm afraid the editing of such one big source code file would be slowed down considerably. I could maybe pack these stringified resources in a second file and $.evaluateFile() it...
Yet in the past I've had random failures with stringified images (possibly because the string was exported as binary? Who knows) - do you have any other suggestion?
I've even thought about stripping few bytes from the JPG files and add them back at runtime. I don't know whether it's worth the hassle - and by the way these images would serve as "fixed" previews for the GUI (that is: the user tweak radiobuttons and the preview Image loads a new JPG to match the new setting - that's the why I have lots of jpgs), I'm wondering whether it would add an unwanted/noticeable delay.
Thanks in advance for any suggestion!

Davide Barranca
http://www.davidebarranca.com
undavide

Packing/Concealing external resources

Post by undavide »

One thing that appears to work (I haven't tested the speed) is:

1. Stringify the myFile.JPG
2. Open the TXT file in ESTK, it looks like: "\u00FF\u00D8\u00FF\u00E1\x00\ ... "
3. Export the TXT to Binary without extension - now the file is somehow locked
4. in the script:

Code: Select allvar w = new Window('dialog');
w.i = w.add('image');
var img = $.evalFile("/TEMP/myFile");
w.i.image = img;
w.show();

I'm wondering whether it would make any noticeable difference if I store all the images in vars while initializing the dialog, or just loading them when needed.

Davide
undavide

Packing/Concealing external resources

Post by undavide »

Further testing has shown a couples of ScriptUI bugs (correct me if I'm wrong).
I've stringified and exported as binary two jpgs, that are now files with no extension on my Desktop:

Code: Select allvar imgObj = {
    'one': $.evalFile("~/Desktop/Harbor"),
    'two': $.evalFile("~/Desktop/Woman")
}
var w = new Window('dialog');
w.i = w.add('image');
w.i.image = imgObj['one']; // renders correctly
w.cb = w.add('checkbox');
w.cb.text = "Change image source";
w.cb.onClick = function() {
    w.i.image = this.value ? imgObj['one'] : imgObj['two'];
}

w.show();

The above script builds a Window with a Harbor image in it, and a checkbox which status controls (i.e. switch) the image source.
Now, randomly it gives the error: "Unable to create temporary image file".
When it randomly works, the checkbox doesn't switch the image.

But if you build the script in a way that the checkbox changes the image source two times:
1. to an actual JPG file
2. to the stringified/binary extensionless image
it works.

Is this life?!
Davide Barranca
undavide

Packing/Concealing external resources

Post by undavide »

For those interested in using stringified images, this topic in the InDesign scripting forum deals with that:

http://forums.adobe.com/message/5661259#5661259

Davide
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: Packing/Concealing external resources

Post by schroef »

@undavide,

do you perhaps now the title of the psot. The devs of Adobe kinda screwed over the forum when they did the redesign a while back. Cant understand they didnt try to keep old urls or somehow convert them?!?