How to display a local image by Chrome extension?

3,170 views
Skip to first unread message

Amanda

unread,
Jan 21, 2011, 3:55:50 AM1/21/11
to Chromium-extensions
I want my extension to display an image. The image need to be found
from my system by a plug-in, and the plug-in can get the path of the
image file.

Then how can the plug-in pass the image to the extension to display
it?
I guess it's wrong to pass the the file path because the extension can
not access local files.

Amanda

unread,
Jan 21, 2011, 3:55:58 AM1/21/11
to Chromium-extensions

PhistucK

unread,
Jan 21, 2011, 4:57:26 AM1/21/11
to Amanda, Chromium-extensions
- You can convert the content of the image file into a base64 string (using an external library, I believe there are open source ones) and pass it back to the extension. Chrome can display (base64 and others) data URIs.
- If you are able to fetch the path of the plugin (not sure you are), then you can just copy the image files to the folder of the extension and fetch them as usual.

PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Amanda

unread,
Jan 23, 2011, 10:24:17 PM1/23/11
to Chromium-extensions

Thanks a lot, PhistucK!

> Chrome can display (base64 and others) data

Could you tell me the Chrome method to display the data after getting
the base64 string?
Can I use javascript like img.src="data:image/png ...."?

And I also wonder why Chrome can not accept the original content of a
image file?

Many thanks!


Ben

unread,
Jan 23, 2011, 10:59:34 PM1/23/11
to Amanda, Chromium-extensions
Reply in-line...

On Sun, 23 Jan 2011 21:24:17 -0600, Amanda <mengdo...@hotmail.com>
wrote:

>
> Thanks a lot, PhistucK!
>
>> Chrome can display (base64 and others) data
>
> Could you tell me the Chrome method to display the data after getting
> the base64 string?
> Can I use javascript like img.src="data:image/png ...."?

Yeah, that should work. (would be img.src="data:image/png;base64,[...]" )

>
> And I also wonder why Chrome can not accept the original content of a
> image file?

It may be able to; I'm not familiar with npapi and how binary data might
be passed from the plug-in to the browser, or how and if javascript can
handle such data after receiving it.

>
> Many thanks!
>
>


--
Ben

Amanda

unread,
Jan 28, 2011, 3:19:24 AM1/28/11
to Chromium-extensions
The plug-in can read the image file and convert the content to a
base64 string.
But how can I let the plug-in pass the string content to the
extension?


And after extension get the string, how can I fit data into
img.src="data:image/png;base64,[...]" ?
I can not hard copy the string data into [ ].\

Thanks!

PhistucK

unread,
Jan 28, 2011, 5:57:48 AM1/28/11
to Amanda, Chromium-extensions
I guess... using https://developer.mozilla.org/en/NPN_Invoke.
This is the way to execute JavaScript code.
So you have your base64 string and you prepend data:image/png;base64, to that string and then you return\call a function with that string, that will just set img.src to be that string.

PhistucK



Reply all
Reply to author
Forward
0 new messages