Snippet List
If you want to resize transparent PNGs with the `{% thumbnail %}` templatetag, they'll sometimes get an ugly black background that looks even more ugly on a white background. This processor puts the image on a white background. You can simply change the background color by replacing `white` with any other color.
To use this filter simple put the following two lines of code in your settings file:
from sorl.thumbnail.defaults import PROCESSORS as THUMBNAIL_PROCESSORS
THUMBNAIL_PROCESSORS = ('path.to.white_background',) + THUMBNAIL_PROCESSORS
- png
- background
- sorl.thumbnail
This view assumes you have downloaded [modelviz.py](http://django-command-extensions.googlecode.com/svn/trunk/extensions/management/modelviz.py) and placed it in a python module called utils within my_project. You also must have graphviz installed and a subprocess-capable python. From there you can feed it a URL query list of the options you want to pass to generate_dot, and it will dynamically draw png or svg images of your model relationships right in the browser. All it wants is a nice form template for graphically selecting models. Most of this code and the main idea thereof was shamelessly plagiarized from [someone else](http://gundy.org/).
Examples:
`http://localhost:8000/model_graph/?image_type=svg&app_labels=my_app&include_models=Polls&include_models=Choices`
`http://localhost:8000/model_graph/?image_type=png&all_applications&disable_fields&group_models`
- models
- graph
- png
- database
- graphviz
- modelviz
- visualization
- svg
This is an example of how I am providing downloads of dynamic images in either PNG or PDF formats. The PDF format requires ImageMagick's `convert`, and temporary disk space to save the intermediary image. If anyone knows a way to avoid writing to disk, I'd be happy to include it here.
I realize there may be uses where it isn't necessary to use the PIL Image class if the image is already stored as a file. This is used for downloading dynamic images without saving them to disk (unless pdf format is used).
- pdf
- png
- custom-response
- subprocess
**The code is a bit messy and may include bugs ;-) Anyway, I want to clean it up and add features (see below).**
The `process_latex()` function will read the given template, render it with a custom context and convert it into the desired output format by running it through pdflatex.
Depending on the `outfile` parameter, the output will either be returned (for a response object) or written to the path specified in `outfile` (useful for `save()` in models which generate static, unique files).
**TODO**
* Error handling in case pdflatex breaks (non-zero return value)
* Optionally returning a HttpResponse with the correct mimetype and Content-Disposition set to attachement and an appropriate filename
* RequestContext instead of Context (passing the Context object instead of a dict)
**CREDITS**
Credits also go to ronny for the names dict :-P
- template
- django
- pdf
- dvi
- png
- latex
- pdflatex
4 snippets posted so far.