On May 16, 2012, at 4:30 PM, Jeremy Walker wrote:
>
>
> On 16 May 2012 21:20, regedarek <
dariusz...@gmail.com> wrote:
> I get image url via API. It usualy have 360x200 but sometimes 233x350 etc..
>
> I would like to crop them all to specific size 260x186. And show them using
>
> <%= image_tag image_url if hotel.images.first %>
>
> I dont want to store this images.
>
> You can use rmagic to crop the images but there's going to be a time-cost here if you don't have the images stored. Probably the best bet is to have image_url hit your application, crop the image and then use send_file, then delete the image.
>
> You might not want the request to go through your whole Rails stack here from a load POV. 10 images per page = an extra 10 requests to your application and these requests will take a bit of time to process the image so you could end up blocking actual requests. I'd setup a separate app using either using Sinatra, or a cut-down version of Rails with just the necessary stuff loaded. There's also a big risk of caning your CPU here, if you have high volume.
>
> Storage is cheap - why not store them?
>
> tl;dr; Real-time image-cropping strikes me as a bad idea, but you could use rmagic on a separate application/server to do it.
Take a look at Dragonfly, too. You get an API to use ImageMagick against your photos -- to crop, scale, grayscale, whatever -- and the images are cached. It runs in Rack, so it's a ready-to-roll solution rather than you having to build a Sinatra app to do this. The only downside is that, out of the box, the URLs are amazingly long.