“Best” way to generate ~500 smallish images, either in JavaScript or server-side C

久未见 提交于 2019-12-13 17:54:27

问题


This is my very first attempt at generating images on the fly.

I want to display around 500 small -- say, 32px X 24px -- 16-color images, each in a table cell. Each image (as I see it now) is a 2D array of colored pixels, each representing a value furnished by C-language CGI.

The finished, displayed image is a prmitive candlestick graph, each candle one pixel wide, something like: http://www.sellmycalls.com/pics/candle-sample.png

All of the ~500 images want to be available for redisplay every 10 seconds, although:

  • only around 30 of these guys show up in the viewport at any instant; and
  • the images change only every ~10 minutes.

I can generate the images on any combination of the server and the client. But I need a general strategy to get me started.

What's the lightest-weight (no huge JS lib, I hope), quickest (implementation), fastest (execution), and cheapest (client-side RAM) to get these images displayed?

Thanks!


回答1:


If you ask me what is the

  • fastest
  • quickest
  • cheapest

I have no dubt about it:

http://code.google.com/apis/chart/

You can delegate all the dirty job to google' server.

And that's not bad at all.




回答2:


Another option should be to simply use Canvas. Simply draw each candle onto the canvas according to to the values generated by your C CGI. You can fetch those values through a simple AJAX call into the client.

No JS library required. The canvas API is trivial, a few lines of code will generate your images. It should execute fast enough so that the user won't even notice they are generated dynamically (that is 30 images / viewport). And it is not much more expensive than displaying static images for the client RAM and also will not produce any additional load on your server.



来源:https://stackoverflow.com/questions/6204079/best-way-to-generate-500-smallish-images-either-in-javascript-or-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!