AE ENHANCERS

Expressions/Scripts/Presets
It is currently Tue May 21, 2013 12:00 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Reading the (text) contents of a GIF
PostPosted: Sun Jan 31, 2010 4:33 pm 
Offline

Joined: Tue Jul 07, 2009 5:18 pm
Posts: 11
Hi guys,

I am working on a script to basically insert a gif as metadata into a fx preset file. If you open Adobe bridge and browse to the After effects text presets you will see that you can click on a preset and in the preview there is an animated GIF. So I am attempting to do this for custom presets.

Basically I think I need to read the contents of a GIF file as data, or text, then encode that as base64 and insert it into the metadata of the preset file.

The problem is when I read in the GIF as data I can't seem to get all the data.

The code I'm using is
Code:
file = new File("C:\\test.gif");
file.open("r");
test = file.read();
alert(test);


And what gets returned is
Code:
GIF89aØ


If I open the gif in notepad I get:

Code:
GIF89aØ   ô     ÿÿÿ–••øøøòòòìììæææàààÛÛÛÕÕÕÐÐÐÊÊÊÅÅÅ¿¿¿¸¸¸°°°¨¨¨ŸŸŸŒŒŒƒƒƒ{{{rrriii___VVVMMMCCC999///### !ÿ NETSCAPE2.0   !ù ÿ ,    Ø    ÿ  Ždižhª®lë¾p,Ïtmßx®ï|ïÿÀ pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ 
H° Áƒ*\Ȱ¡Ã‡#JœH±¢Å‹3jÜȱ£Ç CŠI²¤ÉE!  !ù ÿ ,! C    VàdYJ›Tlë¶HF½4œe¥KM+è: @,JZ›¢Ré9²†Ë¥gÆJF—Î ôJl¶¶\@|õVÃÆ/`Ö®ÅjtÛŠ¯§ñp›|¥è\{ovK! !ù ÿ ,0 I    ˆ TŒ`š[3Y‹w—ôÛ,í Å&9q¯jñBœ2ˆEìzÂWK‹Šk Bx0ÀÆk™   ]¬L’kâx¿[ù$.0 n&-;
‚&L;E‰ ; AŽ;dŽ yŽ5/
˜CMt'^%‰6_˜L›˜fœ˜! !ù ÿ ,@ H      Ž¢·qd   dM ’7z,…ì‹MI0›-¿†ÍCô   l KOv0P‘Åñ\e™Ô&(X›!‰Ó p¾é '{£Õ#¶ÏÛ,„I 2|>.$R2g?#H`Œ?‚X“‘?(“‰ƒYpjY7wr)§®$°±Cƒx±p´%«´! !ù ÿ ,C H    ë  ŠÞƍh
p¦ZP@Öt!y*àQØ'Q@ èùh‹M*³8ú’Bca86p¢Mó'¸4Œ“O€µ’ ©]z €FFY|Ç(GAè4)3?"wP84am#k4'N›I’”#˜ ¡›Gž)–>—D±±ƒ(Z4"º·9s0vFu>ÃÀ>} U‚$†6*X¦Ï€#gŠ
MbØGá)äGP’f>Xªéb“"òÀ$-P¤òG0ÇÀ‚…äK˜ð C‚?>=ô×o"° !ù ÿ ,a I    ªàUŒ`R ×   d*"qE@®U‚KÙ… `akpN[ á9Al Ó/€¢ʪ)eë8@‹    J/lð´óJl ©!\ÉÛñà.6 |scPDO,DV[5"%6‡6.&|yG]u7 ˜K
KM« «-’5h?#MŠJ€„J
§(SeG&޲Ç/;.yË&! !ù ÿ ,y H
  =  Ž€·™MQœRPÛâf[Àu ¹.ÅÉ<%ãáä
Òæè!m$À3°ˆNÖ\Õ™Ã*»Y×vt
¼£ !ù ÿ ,„ B    0  x¢(ÁdH,×¾âÖHd©ïÜR
€ÌŠ3$Q˜d.Ê£S
F¯V@ !ù ÿ ,ˆ E    bàŒd&q$à¥R[*KÁˤPÃi£¶µ`¡ ðø<º âZ®¢ 1¦’<’/çÊŽ¶#ìí{ݍ`€¸wížÓk-kwa“(Qˆ}tA(h2
Ji?JU8$+ ! !ù ÿ ,– H    k  ŽÞƍèH!A'ʱn½‘K[@T葤…ÈŒ2¬‚àI.Q"À’42™”bC©y]EÉï[+d†-ˆ`Í^K<–Ÿ9•B¦é©†KDõ4  c_7$+^0x%& ! !ùF ÿ ,£ H    S  ޤÇq$…PE •MX‚-{žèA¶šN ˜~º@ArA-zHÛ“„Ø…    €È¶- àÄ(ø,öaÛ¾5ü«÷èá­õZߢðl$! ;




So am I doing something wrong in reading in the gif? Do I need to specify some sort of encoding?


Top
 Profile  
 
 Post subject: Re: Reading the (text) contents of a GIF
PostPosted: Sun Jan 31, 2010 9:50 pm 
Offline

Joined: Tue Jul 07, 2009 5:18 pm
Posts: 11
If i copy the data to a txt file, and remove the "GIF89aØ" at the beginning, the rest of the data reads in fine.

So I guess javascript is getting stuck on the "GIF89aØ". Any ideas?


Top
 Profile  
 
 Post subject: Re: Reading the (text) contents of a GIF
PostPosted: Mon Feb 01, 2010 8:14 am 
Offline
Enhancement master
User avatar

Joined: Thu Jun 17, 2004 9:27 am
Posts: 456
Location: New York City, NY
Might be a PC thing. Just tested your test script on mac and I get the full text.

-Lloyd


Attachments:
Screen shot 2010-02-01 at 10.09.08 AM.png
Screen shot 2010-02-01 at 10.09.08 AM.png [ 193.59 KiB | Viewed 791 times ]

_________________
http://aescripts.com
Top
 Profile  
 
 Post subject: Re: Reading the (text) contents of a GIF
PostPosted: Mon Feb 01, 2010 8:48 pm 
Offline

Joined: Tue Jul 07, 2009 5:18 pm
Posts: 11
Thanks for testing it :D Atleast it narrows down the issue.

I've been testing it a little more and if i 'seek' to a specific byte number before reading the data, I can read parts of it in.

E.g. If I seek to byte 14 I get a portion of text up until it encounters white space. It seems whenever there is some whitespace (like directly after the GIF89a part), it stops reading it.

Maybe its a encoding issue, and I don't have the correct encoding on my system.

Would you be able to run it again with a

Code:
alert(file.encoding);


after the read command?


Top
 Profile  
 
 Post subject: Re: Reading the (text) contents of a GIF
PostPosted: Tue Feb 02, 2010 7:55 am 
Offline
Enhancement master
User avatar

Joined: Thu Jun 17, 2004 9:27 am
Posts: 456
Location: New York City, NY
Here you go. Have you read over the File encoding chapter in the Javascript Tools Guide CS4?


Attachments:
Screen shot 2010-02-02 at 9.52.51 AM.png
Screen shot 2010-02-02 at 9.52.51 AM.png [ 23.71 KiB | Viewed 782 times ]

_________________
http://aescripts.com
Top
 Profile  
 
 Post subject: Re: Reading the (text) contents of a GIF
PostPosted: Tue Feb 02, 2010 7:09 pm 
Offline

Joined: Tue Jul 07, 2009 5:18 pm
Posts: 11
Yea I have read over it. I have tried to read it with a bunch of different encodings but get the same result each time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group