Ask HN: image scaling on the fly
Hi,
I've built some mobile sites & apps the last few years and rescaling images keeps popping up.
Ideally I would want something like this:
http://scal.er/w40-a1:1/http://path/to/image
this would generate a square thumb, 40x40.
I would be willing to pay for such a service.
27 comments
[ 3.3 ms ] story [ 77.1 ms ] threadI have used imagemagick/GD previusly, but there are some hassle involved in setting up this for each project/client (cron job for cleaning up thumbs, space considerations, not all ISP I use for clients have GD installed etc)
I agree that writing an ad-hoc image scaler is simle.
However, writing a quality general one that handles different formats, image quality, aspect ratio, smart cropping etc..is not trivial.
Also, you are going to be limited to the tools for processing images that are out there for the most part, which sadly means ImageMagick and/or GD. But not SO sadly, as both of those (while annoying to deploy, granted...) have decent bindings to everything, support a pretty good selection of images types, and have params for controlling the aspects you mentioned (except maybe smart cropping).
Everything else is arithmetic and designing a clean, RESTful URL scheme for invoking it. I guess I meant trivial in the sense that all these things are solved problems or only require a bit of time/cleverness.
I built one of these a few years ago using PHP/GD, and it performed admirably (and did everything except smart cropping in your aforementioned list...)
So, feel free to hit me up if you get stuck on any specifics. Been there done that, and can commisserate if nothing else. ;)
I have used it to create thumbnails for a demo website and they looked OK. Does it have any performance/ aliasing/ whatever issues I'm not aware of?
You should set up a landing page at least, so visitors don't just see /www directory.
It looks interesting but I found the documentation page to be pretty lacking. The simple example they show just allows you to pass a height and width parameter, but the home page says you can do cropping, watermarking, etc.
You can pass other info in the outputs hashes, like labels, your own ids, or whatever. That extra info will be passed back to you in the response JSON.
So I assume it is a case of emailing them and asking for an exhaustive list of what can be passed to their api, the documentation definitely needs work.
http://dyn4.media.forbiddenplanet.com/products/2148557.jpg.s... http://dyn4.media.forbiddenplanet.com/products/2148557.jpg.s...
Basically, if you chop off the dyn4 sub-subdomain and everything after .jpg you can see the original unmodified image. You can also change the extension at the end to change the format of the image (jpg,png or gif). We cache the files to /tmp which we periodically clear out. Whilst it might be more efficient of going down the route of pre-generating all the images we'll need, it's very convenient being able to do it on the fly and to be honest for a site of our size (225,000 visits/month) it's barely a spec on the CPU load of our media server.
There's also an apache module that uses ImageMagick to do something similar:
http://github.com/beetlebugorg/mod_dims
I have to be honest though, I prefer the API for my version and it gives the files a meaningful name in the /tmp folder as well as the user's internet history.
Unfortunately my version isn't open source (yet?) and the code is a bit of a mess, but it's something we have considered opening up.
If you want one developed, please contact me, my email is on my blog @ http://www.adverseconditionals.com
If you are running your own site, and using nginx, there's an image processing module for it that is a match for your requirement: http://wiki.nginx.org/NginxHttpImageFilterModule