Continuation
Continuation

Reputation: 13050

How to specify size of thumbnails for photos that are hosted externally?

I'm building an auction website (in Python/Django). Users can provide URL's to their product images stored in external sites, for example images stored in Photobucket.

So my plan is that when displaying a specific auction, I'll link to the external product image. But when I'm showing list of auctions (e.g. a search results page) I'd need to show the thumbnails

I can see 2 options of doing this:

  1. Use the externally hosted images as thumbnails as well. Specify a standardized small size for these images to "turn" them into thumbnails. How do I do that - do I specify the thumbnail size in the CSS or somewhere else? What would be a good size? Any code examples would be greatly appreciated as I'm not too familiar with CSS or HTML.

  2. When the user submits an URL to an external image, download that image to my own server and turn it into a thumbnail. Any Python/Django software I can use for downloading the remote image and then turning it into a thumbnail?

Any general advices are appreciated. I'm leaning towards option (1) because I only have a cheap VPS and option (1) would be much less resource intensive. Any reason that is NOT a good idea?

Thanks.

Upvotes: 0

Views: 708

Answers (2)

Spacedman
Spacedman

Reputation: 94222

I'm fairly sure I saw something exactly like this recently, where you could point a Django model field to a remote image URL and have thumbnails done, but you could also have it upload the image files too. Darned if I cant find it now.

Ah ha! Maybe sorl-thumbnail. Gives this example:

{% thumbnail "http://www.aino.se/media/i/logo.png" "40x40" crop="80% top" as im %}
    <img src="{{ im.url }}">
{% endthumbnail %}

Assuming you can replace a literal string with a URL field (and not an ImageField) from your model ( lot.remoteimageurl for example) then I think that's it.

sorl-thumbnail will handle thumbnail creation and caching for you.

http://thumbnail.sorl.net/index.html#

Upvotes: 1

Assaf Lavie
Assaf Lavie

Reputation: 76063

Both will work.

  1. The first option might mean that very large images will need to be fetched and then resized by the css/html. So the risk here is slowness (too much bandwidth being consumed) and ugly resizing of images (depends on the browser).
  2. Resizing the images yourself might be a very good strategy. You'll get predictable thumbnails and faster load times. You can use caching to make sure the resized thumbnails don't get computed every time.

I'm guessing that, if you googled for it a bit, you might even find an image resizer as a REST service, so you won't even have to implement it yourself (even though it's trivial) - you could just concatenate the url to some resizer service's url and be done with it.

** Edit **

Some googling found these tools:

Upvotes: 2

Related Questions