A lot of websites are starting to offer generated image banners for server admins to display live stats on their websites. As a lot of our customers have requested this from us for a specific server type, I started looking into it.
Here is an mockup I did for explanation...
1) Basically I will have this image minus the white text as a 开发者_JAVA百科template. What would be the most efficient way to do this, since we will most likely have quite a few of these? Should I just have it rebuild the image when someone views it (query server/build new image), or should I query the server every X minutes, keep data in database, and rebuild image every X minutes?
2) The text on it now is a custom font with white text and a 2px black stroke. Can I use custom fonts with stroke effects in PHP when generating it?
3) For generating a (Players over last 24 Hours Graph) I was looking at Figure B for Bar Graphs. Would I just put a background image on the banner, and then draw the bar graph over the top of it based off data from the database?
the most efficient way is to generate the image the least amount of times. There would is no point quering the database every x minutes to generate these images if people only look at the graph twice per day, for example.
If performance becomes an issue, you can cache the output image for x mins and only requery the database after that time. (it depends on how fast the data changes) Also if you want to keep load off you main server, this is an ideal task for using a secondary server.
Font handling in php is fairly limited. have a look at gd for image handling.
Like you mention, you best bet is to render the graph, then overlay that image and the text on the background image you have designed.
For #1, you should query every X minutes. You could speed it up more by checking if anything actually changed, as well. Rendering images through PHP can be costly (at least in my experience) and you'll definitely want to minimize how often you do it, especially if you have a lot to do.
精彩评论