views:

520

answers:

2

I have a combination of client-side technologies creating PNG data in the browser. Is there a way to convert the PNG data to GIF for display in IE without sending the data to the server? Wondering if there is an existing JavaScript library that will parse the PNG data and output GIF, or even JPEG. I know that I can send the PNG data to a server and have PHP / Python / or whatever generate a file for display in IE, but I'm aiming to keep this all on the client side even if the processing of the image is somewhat slow.

UPDATE: No obvious existing JavaScript libraries to do this, so I'll use Flash to convert image data to GIF output for IE and continue to use PNG for all other browsers.

+6  A: 

Is it possible? I suppose. JavaScript is Turing-complete, and I suppose one might be able to get around browser restrictions by outputting an <img src="data: ..." /> sort of format.

Is it feasible or a good idea? Hell no. Doing this would be like needing some concrete and developing a Moon rocket to harvest lunar dust to make it instead of buying some at Home Depot.

ceejayoz
Few analogies drive a point home with such eloquence.
rpflo
I am not sure about this being possible, but why is this a bad idea? This seems to be a pure UI/display problem, and if it is possible to resolve it on the browser, that is a very good idea, I think.This is the same idea as creating charts in the browser with JavaScript as opposed to having image files created server-side.
Thilo
It's a bad idea because you could do it once server-side instead of every single session client-side. It's a bad idea because server-side libraries like ImageMagick and GD are going to be massively faster at doing it than a language like JavaScript that simply is not set up for doing heavy calculations required in image manipulation. It's a bad idea because there simply isn't an existing solution that I'm aware of client-side while there are lots of server-side ones.
ceejayoz
As for creating charts in the browser with JavaScript, the JavaScript isn't doing any image manipulation there. It's either manipulating some HTML, or sending instructions to Flash or some similar tech that's doing the heavy lifting imagewise.
ceejayoz
Well, he already has a solution to creating PNG files in the browser. Does not seem to be a big step from there.
Thilo
The heavy lifting of converting PNG to GIF could also be done by "sending instructions to Flash or some similiar tech", just like with the charts.
Thilo
Being able to do it and it being a good idea are entirely different issues. Creating PNGs on the fly with JavaScript is bound to be a slow, CPU heavy process.
ceejayoz
Being able to do it and it being a good idea are different issues. I have doubts that it is possible (but he is already creating PNG in the browser, so maybe it is), but if it is possible it would be a very good idea. It seems to be much less CPU heavy than playing a YouTube video, for example. And farming out CPU work on clients rather than concentrating it on the server is also a sound scalability approach. I really cannot see how this is conceptually different from the JS charts.
Thilo
"It's a bad idea because you could do it once server-side instead of every single session client-side." How could you do it once server-side if the input PNG is generated on the client and presumably different every time. You would have to do it for every single session (or request) server-side.
Thilo
The PNG data is created on the client side; final output is from Flash. The issue of doing it "once server-side instead of every single session client-side" is not relevant here, because every client gets a completely different image, so there's no advantage to a server call from that perspective. I'd like to stick with PNG for all browsers that support it as the images look best as PNG, and only use GIF when necessary. If there's no JavaScript lib to help with this, I could use another Flash file to convert from PNG to GIF but I don't think Flash has native support for GIF output.
JR
A: 

It seems that you have a Flash object that outputs PNG. Can you add a JPEG or GIF output option to it?

As an alternative, it seems there is a JavaScript library that enables PNG support in IE. Not sure how well it works, though.

Thilo