Last active
December 10, 2015 14:08
-
-
Save zmsmith/4445844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from libthumbor import CryptoURL | |
def thumb(url, **kwargs): | |
''' | |
returns a thumbor url for 'url' with **kwargs as thumbor options. | |
Positional arguments: | |
url -- the location of the original image | |
Keyword arguments: | |
For the complete list of thumbor options | |
https://github.com/globocom/thumbor/wiki/Usage | |
and the actual implementation for the url generation | |
https://github.com/heynemann/libthumbor/blob/master/libthumbor/url.py | |
''' | |
if settings.THUMBOR_BASE_URL: | |
# If THUMBOR_BASE_URL is explicity set, use that | |
base = settings.THUMBOR_BASE_URL | |
else: | |
# otherwise assume that thumbor is setup behind the same | |
# CDN behind the `thumbor` namespace. | |
scheme, netloc = urlparse.urlsplit(url)[:2] | |
base = '{}://{}/thumbor'.format(scheme, netloc) | |
crypto = CryptoURL(key=settings.THUMBOR_KEY) | |
# just for code clarity | |
thumbor_kwargs = kwargs | |
if not 'fit_in' in thumbor_kwargs: | |
thumbor_kwargs['fit_in'] = True | |
thumbor_kwargs['image_url'] = url | |
path = crypto.generate(**thumbor_kwargs) | |
return u'{}{}'.format(base, path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream thumbor { | |
server 127.0.0.1:9000; | |
server 127.0.0.1:9001; | |
server 127.0.0.1:9002; | |
server 127.0.0.1:9003; | |
} | |
server { | |
listen 8000; | |
server_name thumbor.yipit.com; | |
# merge_slashes needs to be off if the image src comes in with a protocol | |
merge_slashes off; | |
location ^~ /thumbor/ { | |
rewrite /thumbor(/.*) $1 break; | |
proxy_pass http://thumbor; | |
} | |
location / { | |
proxy_pass http://thumbor; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[program:thumbor] | |
command=/var/www/thumbor-env/bin/python /var/www/thumbor-env/bin/thumbor --port=900%(process_num)s --conf=/var/www/thumbor-env/thumbor/thumbor.conf | |
process_name=thumbor900%(process_num)s | |
numprocs=4 | |
user=ubuntu | |
autostart=true | |
autorestart=true | |
stdout_logfile=/var/log/supervisor/thumbor900%(process_num)s.stdout.log | |
stdout_logfile_backups=3 | |
stderr_logfile=/var/log/supervisor/thumbor900%(process_num)s.stderr.log | |
stderr_logfile_backups=3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment