My next project will be a kind of online photo viewer. All of these
will need to have watermark applied to them. The problem is that,
on the picture, different watermarks need to be applied, exclusivelly
all in the same image). The easiest solution would be to process these
picture at runtime using RMagick, apply the watermark(s) and serve them.
other approach, would be to pre-process them (also using RMagick or the
ImageMagick CLI tool) and create different copies on the disk for each
watermark, the obvious advantage being that it could be served directly
the webserver (apache) using x-sendfile, but, it would be much harder to
manage (need to fix a watermark error? Re-process and re-create the
on the disk…) and would take much more disk space (which could
solved by using a distributed filesystem, though).
One thing that I thought could work is to have a dedicated (or a
server to process the images, this server (or cluster) would receive a
request from the web server(s), process the desired image and return the
stream of bytes to the web server that would in turn delegate it back to
client with the right mime/type (image/jpg). The software to process the
images could be written in C to better optmize things. This, I think,
solve the CPU/RAM problem for processing the images per-request at
but would result in a rather expensive backend. However, I’m not sure if
passing the stream of bytes through Rails is optimal and I think it
a major bottleneck, since I’ve heard of memory leaks and other hairy
when you try to serve big files using Rails - is that true?
I would rather process them at runtime (more flexibility (code can
per request, which watermark(s) to apply), much less disk space (in the
other approach I would have to keep several versions of the pictures for
each watermark(s)) per HTTP request, however, this site will probably
lots of traffic. So, I’ve reached a deadend. Could someone share his/her
experiences and thoughts and help me decide?
PS: I’ve put DoS in the subject tagline meaning Denial of Service as I
that maybe dynamic processing of images VS lots of request could result
Thanks in advance,