Skip to main content
Known Participant
March 14, 2008
Question

How can I let the png images pack into .jsx files?

  • March 14, 2008
  • 14 replies
  • 4608 views
I want to design an interface by iconbutton control,but I don't know how to pack the images into .jsx files.

By the way,I have seen anybody's scripts which designed by that way.
This is the URL:
http://www.cooldtp.cn/bbs/viewtopic.php?t=84627

Anyone can give me some advice or some examples?

Thanks a lot!

Goldbridge
This topic has been closed for replies.

14 replies

Known Participant
March 24, 2008
Hi,Bob

Thanks a bunch.It does work well.

Goldbridge
March 24, 2008
I just ran this on a good png and got good output.

var f1 = new File( [png path] );
var f2 = new File( [text file path]" );

if ( f1.exists ) {
f1.encoding = "BINARY";
f1.open( "r" );
var buf = f1.read();
f2.open( "w" );
f2.write( buf.toSource() );
f2.close();
f1.close();
}

Bob
AYS__HAKKIM
Inspiring
March 11, 2010

Hi

It didn't work for png. But worked for jpg & ico. Only Icon file processing was in acceptable quality but not good. Could any one please suggest on this?

thanks

Ays.Hakkim

Known Participant
March 24, 2008
TO Bob,

I have tested with "png.exists",it returns "true"!

I have no way to find the problem!

Goldbridge
March 21, 2008
Make sure that the File objects reports png.exists == true

Bob
Known Participant
March 21, 2008
I can't get the code like this (new String("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\.... ),it only returns "(new String(''))" ,anyone can tell me why?
Known Participant
March 20, 2008
read "binary"

jxswm
Known Participant
March 20, 2008
TO Bob,Peter

I have placed the png image(1.png) into "c:\ButtonBar".

Then I run the script:

/***********

var png = new File('/c/ButtonBar/1.png' );
var f = new File( '/c/ButtonBar/2.js' );
png.open( "r" );
var buf = png.read();
png.close();
f.open( "w" );
f.write( buf.toSource() );
f.close();

/************

But this script doesn't work,it only returns this code "(new String(''))" in "2.js".

Can you tell me why?Thanks a lot!
Peter Kahrel
Community Expert
Community Expert
March 20, 2008
>How can I save the script(included a png) as jsxbin?

File > Export as binary.

Peter
Known Participant
March 19, 2008
Bob,Peter:

My friends,thanks a bunch!
Bob's answer is very well,I'm going to have a try!

To Peter:

How can I save the script(included a png) as jsxbin?
March 19, 2008
When he said "pack" them into the jsx files, that's what came to mind.

I use the technique when I want to have a set of images, but don't want the user to have to deal with putting images into correct places.

A new version of my script library uses it for a widget that adds a flyout menu to any ScriptUI window, for example. I don't want the user to have to put an image in a correct place, so the script does it for them.

You can save it as a jsxbin.

The only thing to watch (that I've found so far) when saving to jsxbin are classes that get serialized with toSource().

For example, in my lib, the Hashtable and Preferences class will have instances serialized and reconstituted...

From the lib:

BobsLib.Preferences.prototype.load = function() {
var oldLevel = $.level;
$.level = 0;
if ( this.file ) {
if ( this.file.exists ) {
this.file.open( "r" );
var buf = this.file.read();
this.file.close();
var obj = eval( buf );
this.merge( obj );
} else {
$.level = oldLevel;
throw "Preferences Not Yet Saved";
}
} else {
$.level = oldLevel;
throw "Preferences File Not Set";
}
$.level = oldLevel;
this.wasLoaded = true;
}
BobsLib.Preferences.prototype.save = function() {
if ( this.file ) {
this.file.parent.verify();
this.file.open( "w" );
this.file.write( this.toSource() );
this.file.close();
} else {
throw "Preferences File Not Set";
}
}

After a Preferences instance is saved, it can't be loaded because the eval() fails. Looks like the constructor isn't available as text causes the problem.

Bob