We provide a library for Python and for Django. The Python module makes it easy to download your thumbnails, while the Django plugin adds a custom filter thumbalizr to generate the Thumbalizr URL right inside your templates.
The python code to generate a Thumbalizr URL is pretty simple, you can easily copy and paste it into your project:
import hashlib
import urllib
def thumbalizr(url='', options={}):
embed_key = 'MY_EMBED_API_KEY' # replace it with you Embed API key
secret = 'MY_SECRET' # replace it with your Secret
query = 'url=' + urllib.quote_plus(url)
for key, value in options.items():
query += '&' + key + '=' + urllib.quote_plus(str(value))
token = hashlib.md5(query + secret).hexdigest()
return "https://api.thumbalizr.com/api/v1/embed/%s/%s/?%s" % (embed_key, token, query)
print thumbalizr("https://browshot.com/", { 'width': 300, 'size': 'page' })
print thumbalizr("google.com")
You can install the Thumbalizr library with pip: pip install thumbalizr
. You'll find the source code in GitHub
Your API key and Secret can be found in the member section after you sign up for a free account.
from thumbalizr import Thumbalizr
thumbalizr = Thumbalizr(MY_KEY', 'MY_SECRET')
url = thumbalizr.url('https://www.google.com/');
print(url)
results = thumbalizr.download_wait(url);
print("%s" % (results[0]))
Add the thumbalizr_django app to your Django project to use the thumbalizr custom filter in your templates. First, add the library to your list of installed apps in settings.py:
# settings.py
INSTALLED_APPS = [
...
'thumbalizr_django'
]
Then, add your global settings in the same file::
# settings.py
THUMBALIZR_SETTINGS = {
'API_KEY': 'MY_KEY',
'SECRET': 'MY_SECRET',
'WIDTH': '',
}
You can set any of the API parameters supported: COUNTRY, DELAY, etc.
Your API key and Secret can be found in the member section after you sign up for a free account.
Now, you can call thumbalizr inside your templates to generate the Thumbalizr URL of your thumbnails. You can pass pass the width of the thumbnail:
{% load thumbalizr_tags %}
<img src="{{ 'https://www.thumbalizr.com/'|thumbalizr:800 }}"/>
You can find the source code of the Django extension on GitHub.