On Image Uploads and Thumbnailing
I’ve been thinking lately about images and thumbnails. Supporting images is a complete and total non-budgeable requirement for any software whose audience is real people. People connect with images. Period.
That means that we need to support image uploads, which could be a problem in terms of bandwidth and speed for users uploading from their mobile devices over slow connections. i’m not really sure what the real-world speeds of GPRS/EDGE are these days, but i can’t imagine that uploading a week’s worth of 1.3 megapixel Nokia 7610 photos over a wireless data connection would be much fun. One solution is to only upload files smaller than a certain size, effectively ignoring larger cameraphone pix. But that sucks — the reason the 7610 phone is so hot is that big photos bloody rock! More pixel data means better image quality. Thinking aloud here, i bet that the larger images also downsample better to equivalent sizes, i.e. all things being equal, if you take an 1152×862 image and resize it down to 320×240 with a decent resampling/sharpening algorithm, it would still be better than an original cameraphone image taken with a 320×240 camera. (maybe? correct me if i’m wrong, please.)
We’d prefer to have the highest-resolution photos we can get, of course, but our users shouldn’t have to endure painfully slow uploads just because they have a good phone that takes high-quality pictures. Good phones have good processors and a decent amount of space, usually, which means we could thumbnail the big photos our self in the upload process and just upload the smaller ones, saving the user a longer upload time.
Enter: EPEG.
RASTERMAN (of the enlightenment window management desktop suite) says:
2004-01-31 13:46:44.000000000 +0900 Epeg
Over the last few days I have addressed something that bothered me greatly while fixing up my web pages. The INSANELY SLOW speed of generating thumbnails for photos.
First, some background. I have a large photo collection. Definitely not the biggest as I can imagine some people have even more extensive collections. I have something like 1300 photos, most of which are 2560x1920 in size. By any stretch this isn't small. When making thumbnails of these images, under Nautilus on my machine the process would take about 1 second per photo. That's a lot of time to thumbnail my collection. Yes they get cached, but every time you rename or move files around they need re-thumbnailing. This really got to me. So I started using Imlib2 for thumbnailing. Great. This gave about a 2-3 times speedup, letting me do about 2 to 3 thumbnails per second. But that just wasn't good enough. I knew I could do better, thus my work on what I now call Epeg was born.
Epeg can thumbnail at about 25 thumbnails per second. Compared to the original speed of Nautilus... this is a decent speedup and worth the effort of using Epeg. Epeg is a library with a small API that lets you load a JPEG file, scale it down (on load) append comments and thumbnail info, save, access the scaled pixel data, load comments and thumbnail info etc. It's small, compact and fast and it's only requirement is libjpeg.
You can get a copy of a preliminary tarball from my Files section. A direct link to the epeg-0.9.0.tar.gz file is here too. It currently has no documentation for the API, but there is sample code for its usage in the src/bin/epeg_main.c file. It should get you at least an 8 times speedup over anything you have been using. I'd highly suggest using this to generate thumbnails of your photo collections. Yes it will require you to patch whatever tools you use, but for those who can program, it's worth it.
If you want to keep up with the CVS repositor of Epeg, access it with:
cvs -d :pserver:anonymouscvs.enlightenment.sourceforge.net:/cvsroot/enlightenment co e17/libs/epeg
Good luck. I'll keep updating this code, but the next major work is some documentation for it. If you find it useful, please let me know and any patches or improvements are welcome.
Note. Any speed figures I have given are on MY machine. Your thumbnailing speed (in thumbnails per second) will vary depending on your CPU, RAM size of photo and thumbnail etc. My tests were RELATIVE. They were conducted on the same source images, outputting thumbnails of the same dimensions on the same machine.