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

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

Community Beginner ,
Mar 13, 2008 Mar 13, 2008

Copy link to clipboard

Copied

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
TOPICS
Scripting

Views

4.2K

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 Beginner ,
Mar 18, 2008 Mar 18, 2008

Copy link to clipboard

Copied

Anyone can tell me the answer?

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 ,
Mar 19, 2008 Mar 19, 2008

Copy link to clipboard

Copied

Did this not work: http://www.adobeforums.com/webx/.3bbf275d.3c065b3a/3 ?

Peter

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 Beginner ,
Mar 19, 2008 Mar 19, 2008

Copy link to clipboard

Copied

This is how I do it:

Write a small script that reads the png and writes it to file like so:

var png = new File( [path to png] );
var f = new File( [a file path] );
png.open( "r" );
var buf = png.read();
png.close();
f.open( "w" );
f.write( buf.toSource() );
f.close();

Then, open the file you just wrote. It should contain a single line that looks something like this: (it will be a very long line!)

(new String("\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\....

Then, in your script, put something like this (note you are copying and pasting the single line above into this script):

var pngFile = new File( [location you want to install the png file] );
if ( !pngFile.exists ) {
var binData = (new String("\u0089PNG\r\n\x1A\n\x00...
pngFile.encoding = "BINARY";
pngFile.open( "w" );
pngFile.write( binData );
pngFile.close();
}

Regards

Bob

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 ,
Mar 19, 2008 Mar 19, 2008

Copy link to clipboard

Copied

Ah -- Bob, you think Goldbridge wants to store the PNGs in the jsx file? In that case, why not save the script as jsxbin?

Peter

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 Beginner ,
Mar 19, 2008 Mar 19, 2008

Copy link to clipboard

Copied

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

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 Beginner ,
Mar 19, 2008 Mar 19, 2008

Copy link to clipboard

Copied

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?

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 ,
Mar 20, 2008 Mar 20, 2008

Copy link to clipboard

Copied

>How can I save the script(included a png) as jsxbin?

File > Export as binary.

Peter

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 Beginner ,
Mar 20, 2008 Mar 20, 2008

Copy link to clipboard

Copied

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!

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 Beginner ,
Mar 20, 2008 Mar 20, 2008

Copy link to clipboard

Copied

read "binary"

jxswm

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 Beginner ,
Mar 20, 2008 Mar 20, 2008

Copy link to clipboard

Copied

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?

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 Beginner ,
Mar 21, 2008 Mar 21, 2008

Copy link to clipboard

Copied

Make sure that the File objects reports png.exists == true

Bob

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 Beginner ,
Mar 24, 2008 Mar 24, 2008

Copy link to clipboard

Copied

TO Bob,

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

I have no way to find the problem!

Goldbridge

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 Beginner ,
Mar 24, 2008 Mar 24, 2008

Copy link to clipboard

Copied

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

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
Participant ,
Mar 11, 2010 Mar 11, 2010

Copy link to clipboard

Copied

LATEST

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

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 Beginner ,
Mar 24, 2008 Mar 24, 2008

Copy link to clipboard

Copied

Hi,Bob

Thanks a bunch.It does work well.

Goldbridge

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