Login

Tag "image"

Snippet List

Template Tag of Django Image Thumb Creator

**You can save these codes into a templatetag file in your django app. Then use codes like these in your template files:** **************************************************************************** {% load *yourtags* %} ... <img src="{% thumb *yourmodel.picturefield* 200 300 0 %}"/> <img src="{% thumb *yourmodel.picturefield* 500 400 yes %}"/> ... The parameters are: imagefield ImageField width Integer height Integer rescale [1, yes, true, 0, no, false] **Some codes come from <djangosnippets.org>**

  • django
  • image
  • templatetag
  • thumb
Read More

Jcrop Form

Implements a Django form that integrates image uploading plus cropping using the awesome Jcrop plugin (http://deepliquid.com/content/Jcrop.html). NOTE: Still lacks proper error handling...

  • image
  • jquery
  • form
  • jcrop
Read More

Thumbnails in admin using django-thumbnails-works

Very straightforward way to display a thumbnail in the admin using [django-thumbnails-works](http://pypi.python.org/pypi/django-thumbnail-works) . django-thumbnails-works requires [cropresize](http://pypi.python.org/pypi/cropresize/#downloadsInstaller) (which requires and installs PIL). Add 'thumbnail_works'to INSTALLED_APPS in settings.py and here you go. Tested in django 1.3 alpha.

  • image
  • admin
  • thumbnail
Read More

Image inlining template tag lib

A custom templatetag for inlining image in the browser. The principe is to base64 encode the image and avoid a http request. There is a cache handling, you just have to specify a writable directory. An example of the utilisation (template part): [http://djangosnippets.org/snippets/2267/](http://djangosnippets.org/snippets/2267/) The explication on [http://raphaelbeck.wordpress.com/2010/11/14/make-inline-images-to-improve-performance-with-django-template-tags/](http://raphaelbeck.wordpress.com/2010/11/14/make-inline-images-to-improve-performance-with-django-template-tags/)

  • tag
  • image
  • templatetag
  • base64
Read More

Image inlining template tag example

The example of the Image inlining template tag lib which inline images in the browser instead of making an Http request. The lib is available at : [http://djangosnippets.org/snippets/2268/](http://djangosnippets.org/snippets/2268/)

  • tag
  • image
  • templatetag
  • base64
Read More

ResizeImageField

ResizeImageField ================ (extension of RemovableImageField) ================================= by Wim Feijen, Go2People. What does it do? ---------------- ResizeImageField is a replacement for django's ImageField. It has two major benefits: 1. Creation of thumbnails and scaled images. 1. Extends the image upload form and adds a preview and a checkbox to remove the existing image. It's easy to use: - Replace ImageField by ResizeImageField - No further changes are necessary Requirements: ------------- Working installation of PIL, the Python Imaging Library Usage ----- - add resize_image to your app - add resize_filters.py to your templatetags - in settings.py, set a PHOTO_DIR, f.e. photos/original - in models.py, add: - from settings import PHOTO_DIR - from resize_image import ResizeImageField - photo = ResizeImageField(upload_to=PHOTO_DIR, blank=True) Scaled images will be stored in 'photos/scaled', thumbnails will be stored in 'photos/thumb'. Access your images from your template. Add:: {% load resize_filters %} {{ address.photo.url|thumb }} or:: {{ address.photo.url|scaled }} Defaults ------- - Scaled images are max. 200x200 pixels by default - Thumbnails are 50x50 pixels. Override the default behaviour in settings.py Scaling is done by PIL's thumbnail function, transparency is conserved. Credits ------ This code is an adaptation from python snippet 636 by tomZ: "Updated Filefield / ImageField with a delete checkbox"

  • image
  • thumbnail
  • resize
  • scale
  • delete
  • ImageField
  • ResizeImageField
  • removable
Read More
Author: wim
  • 5
  • 5

[UPDATE]Filter to resize a ImageField on demand + RATIO OPTION + CLEANUP

This is the snippet of rafacbd but upgraded... (http://djangosnippets.org/snippets/955/) Now support keep the aspect ratio or not, changing the size string (x1, x0) this choice use pil.resize or pil.thumbnail. Remember change the variable CAPS NAMES of the cleanup code. This cleanup function get the original main image file name and create a regexp similar to "[filename]_[width]x[height]x[ratio].[ext]" and remove all thumbs. By example if the main image is spain_rulez.jpg the script remove by example spain_rulez_100x100x1.jpg spain_rulez_200x150x0.jpg etc... etc...

  • template
  • image
  • thumbnail
  • cleanup
Read More

Image model with thumbnail

A relatively simple Photo model which generates its own thumbnail when saved. A default size is specified as `thumb_size` in the `save()` arguments. Other thumbnailing strategies don't save the thumbnail dimensions, and since the actual dimensions of the thumbnail created by PIL's `thumbnail` method are somewhat non-deterministic, it is difficult to create an `img` tag with proper height and width attributes. This approach makes that task simple. This approach works well if only one thumbnail size is required. It could easily be adapted to support two or three thumbnail sizes, but adding more sizes would quickly get unwieldy. This was adapted from http://biohackers.net/wiki/Django1.0/Thumbnail

  • image
  • thumbnails
  • thumbs
Read More

Better Static Image Serving With Fallback

Serves images from a local directory, but if it doesn't find it locally, then go look for it on a server. This is useful for sites with very large amounts of static content. Instead of copying all your prod images to dev every time you update the database, simply use this in your URL patterns to serve the images: `(r'^(?P<path>.*)$', 'static_fallback.serve', {'document_root' : '/path/to/my/files/'})` By default, it caches the images locally in the path it was supposed to find them. The fallback server URL can be specified in urls.py or settings as FALLBACK_STATIC_URL. Thanks to Johnny Dobbins for the idea. Based on the Nginx pass through image proxy concept. For more info [http://menendez.com/blog/using-django-as-pass-through-image-proxy/](http://menendez.com/blog/using-django-as-pass-through-image-proxy/)

  • image
  • static
  • images
  • fallback
Read More

Yet Another Image Resizer

There's a whole range of examples online for resizing images in Django some of which are incredibly comprehensive with a wide variety of options. Here's my take on the task that serves as a simple drop in for when you don't want to include a separate app. - Only generates the resized image when first requested. - Handles maintaining proportions when specifying only a width or a height. - Makes use of PIL.ImageOps.fit for cropping without reinventing the wheel.

  • template
  • tag
  • image
  • pil
  • thumbnail
  • resize
Read More

Updated Filter to resize a ImageField on demand (ver.2)

An update to snippet 1718 (http://www.djangosnippets.org/snippets/1718/). This update lets you pass an image URL string as well as a model ImageField instance. This means that you can then create thumbnails on demand for images outside of model

  • image
  • templatetag
  • thumbnail
  • resize
  • imagefield
Read More

ImageField for admin with thumbnail

AdminImageWidget is a ImageField Widget for admin that shows a thumbnail. Usage example on a form: class IconForm(forms.ModelForm): icon = forms.ImageField(label='icon', widget=AdminImageWidget)

  • image
  • admin
  • thumbnail
  • imagefield
  • widget
  • imagewidget
Read More

64 snippets posted so far.