Scaling imagemagick usage
Posted: 2008-07-05T01:42:36-07:00
I'm looking for ideas on how to optimize my usage of ImageMagick or switch to something else. Here's basically the list of steps I have to do:
- Create a bunch of separate text annotations (in possibly different colors and fonts) that beautifully fits a given space. Currently I do this by making those annotations in a very large point size and then scaling the image down to fit the desired dimensions.
- Put a PNG/GIF background image under the text created in previous step. I accomplish this by having the annotations in the previous step happen on a transparent background, then I overlay that scaled text over the background image in this step.
- Write out as JPEG.
Example: http://tinyurl.com/5wx6nx
These together end up taking anything from 600ms upwards, which is intolerable because I have to serve 20+ such images per second. Currently I am renting 20 Amazon EC2 servers to keep up with the demand, but this certainly is no long term solution! Any ideas?
I'm using command line now in that 600ms+ case. I also did an experiment using the PHP Imagick API, but there seems to be no major speed difference. Got 300ms in my test for just making a single ~1000x100 text and encoding it as PNG. Making identical image took 100ms for GD, but I'm reluctant to use GD as it seems more limited, and still 100ms is pretty slow.
One thing I've been considering is having a font cache like XWindows has and keeping all the characters in memory, then just blit them from in-memory surfaces, scale the result and encode as PNG. I'm really looking for an order of magnitude type improvement here, if I could somehow get this to <50ms then I would only need one server, which would make it much simpler and cheaper too.
- Create a bunch of separate text annotations (in possibly different colors and fonts) that beautifully fits a given space. Currently I do this by making those annotations in a very large point size and then scaling the image down to fit the desired dimensions.
- Put a PNG/GIF background image under the text created in previous step. I accomplish this by having the annotations in the previous step happen on a transparent background, then I overlay that scaled text over the background image in this step.
- Write out as JPEG.
Example: http://tinyurl.com/5wx6nx
These together end up taking anything from 600ms upwards, which is intolerable because I have to serve 20+ such images per second. Currently I am renting 20 Amazon EC2 servers to keep up with the demand, but this certainly is no long term solution! Any ideas?
I'm using command line now in that 600ms+ case. I also did an experiment using the PHP Imagick API, but there seems to be no major speed difference. Got 300ms in my test for just making a single ~1000x100 text and encoding it as PNG. Making identical image took 100ms for GD, but I'm reluctant to use GD as it seems more limited, and still 100ms is pretty slow.
One thing I've been considering is having a font cache like XWindows has and keeping all the characters in memory, then just blit them from in-memory surfaces, scale the result and encode as PNG. I'm really looking for an order of magnitude type improvement here, if I could somehow get this to <50ms then I would only need one server, which would make it much simpler and cheaper too.