Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,617 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 995 people online right now. Registration is fast and FREE... Join Now!




Extracting favicon from NETSCAPE-Bookmark-file

 
Reply to this topicStart new topic

Extracting favicon from NETSCAPE-Bookmark-file, Is it possible?

knownasilya
post 21 Mar, 2006 - 11:44 PM
Post #1


D.I.C Head

Group Icon
Joined: 11 Jan, 2006
Posts: 144


My Contributions


What I want to do is extract the favicon data from a NETSCAPE-Bookmark-file and convert it back into an image. The data from the file looks like this.

CODE
ICON="data:image/x-icon;base64,AAABAAE
AEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAI
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A///
/AI2Njf+NjY3/jY2N/42Njf+NjY3/jY2N/42Njf+NjY3/jY2N
/42Njf+NjY3/jY2N/42Njf+NjY3/////////////////////////////
////////////////////////////////////////////////////jY2N//////
8BbLD/AJz//wCc//8AnP//AJz//wCc//8AnP//AJz//wCc//8
AnP//AJz//wCc//8AnP///////42Njf//////AWyw/wCc//8AnP/
/AJz//wCc//8AnP//AJz//wCc//8AnP//AJz//wCc//8AnP//
AJz///////+NjY3//////wFssP8AnP//AJz//wCc//8AnP//AAAA/w
AAAP8AAAD/AAAA/wAAAP8AnP//AJz//wCc////////jY2N
//////8BbLD/AJz//wCc//8AnP//AAAA/wAAAP8AAAD/AA
AA/wAAAP8AAAD/AJz//wCc//8AnP///////42Njf//////AW
yw/wCc//8AnP//AJz//wAAAP8AAAD/AJz//wCc//8AAAD
/AAAA/wCc//8AnP//AJz///////+NjY3//////wFssP8AnP//
AJz//wCc//8AAAD/AAAA/wCc//8AnP//AAAA/wAAAP8A
nP//AJz//wCc////////jY2N//////8BbLD/AJz//wCc//8AnP//
AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AJz//wCc//8
AnP///////42Njf//////AWyw/wCc//8AnP//AJz//wCc//8AA
AD/AAAA/wAAAP8AAAD/AAAA/wCc//8AnP//AJz///////+
NjY3//////wFssP8AnP//AJz//wCc//8AnP//AJz//wCc//8A
nP//AAAA/wAAAP8AnP//AJz//wCc////////jY2N//////8Bb
LD/AJz//wCc//8AnP//AJz//wCc//8AnP//AJz//wAAAP8A
AAD/AJz//wCc//8AnP///////42Njf//////AWyw/wCc//8An
P//AJz//wCc//8AnP//AJz//wCc//8AAAD/AAAA/wCc//8A
nP//AJz///////+NjY3//////wFssP8AnP//AJz//wCc//8AnP/
/AJz//wCc//8AnP//AJz//wCc//8AnP//AJz//wCc////////j
Y2N//////8BbLD/AWyw/wFssP8BbLD/AWyw/wFssP8Bb
LD/AWyw/wFssP8BbLD/AWyw/wFssP8BbLD//////////w
D////////////////////////////////////////////////////////////
///////////////////////8AwAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAQAAAAEAAA=="


Well I know how to extract, what I want to know is the converting part if possible. And I dont want it done for me, just nudge me in the right direction.

Is there anyway of converting it back to the image? Preferably using PHP. The other option is to actually process every url and retrieve the icon from the individual sites, but this is out of the question..too much bandwidth usage.

This post has been edited by knownasilya: 22 Mar, 2006 - 12:03 AM
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 22 Mar, 2006 - 12:24 PM
Post #2


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,822



Thanked 11 times
My Contributions


Well, everything is on the first line: data:image/x-icon;base64
What you have to do with php is get the part after the comma ending with the double equality sign (==), feed it to base64decode() and write its output into an .ico file.
User is offlineProfile CardPM

Go to the top of the page

knownasilya
post 22 Mar, 2006 - 06:40 PM
Post #3


D.I.C Head

Group Icon
Joined: 11 Jan, 2006
Posts: 144


My Contributions


What would I use to write to an ico or gif file? imagecreate() ?
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 22 Mar, 2006 - 11:57 PM
Post #4


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,822



Thanked 11 times
My Contributions


No, simply open a file in binary mode for writing: fopen($filename, 'w+b')
And write the whole output of base64_decode into it with fwrite.
User is offlineProfile CardPM

Go to the top of the page

knownasilya
post 23 Mar, 2006 - 06:23 AM
Post #5


D.I.C Head

Group Icon
Joined: 11 Jan, 2006
Posts: 144


My Contributions


Ok, thanks. I will do that. What would be the best way to store/save the image. Store the encoded text in db, or decode it and save the image in a directory. This will be done for many icons.. Im not sure which way is most efficient. Or if there are any other ways..

This post has been edited by knownasilya: 23 Mar, 2006 - 06:26 AM
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 23 Mar, 2006 - 07:10 AM
Post #6


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,822



Thanked 11 times
My Contributions


It depends on what are you going to do with them.
If you mainly use them in base64 encoded format, then it might worth the 8/6 size overhead. Otherwise the binary form is a better idea, however storing them in a db or as files is still a question.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 03:13AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month