Saturday, March 27, 2010

Apophnia, an image server

So I was presented with a problem like this:
Hiya, I have a bazillion images and I want to um you know like:
  • Be able to use new resolutions on the fly
  • Have these dynamically created images cached
  • Incur almost zero overhead in the process
  • Have a dedicated image web server or a web server module to do it ... images are important

Basically, given file /myimage.jpg I want to do say, /myimage_500x500.jpg and then say,
  1. Look for myimage_500x500.jpg.
  2. If not found, back up, try myimage.jpg
  3. See that (_500x500) is a resize directive
  4. Dynamically resize myimage.jpg to 500x500, serve that image
  5. Save a new file to disk myimage_500x500.jpg so that when it is requested again ... it's easy

Oh, and I want some other things
  1. When the image is resized the first time, I want it to be the fastest algorithm possible so that the user sees the resized image with minimal delay.
  2. But I also want a different, slow, high quality algorithm to run to save it to disk

One more thing, if it's not too hard
I want to specify things like this:
"medium": {
"resize": [1024,1024],
"quality": 50,
"cropwhitespace": true
so I can do something stupid like request /myimage_medium.jpg

If only this existed! [ Download it here ]

Current implementation details

  • Written in C.
  • Uses Mongoose as a webserver
  • Uses Imagemagick for sizing
  • Doesn't actually do *everything* above yet, but that is the goal.