Dynamic Thumbnail for ImageField
Dynamic Thumbnail for `ImageField` with `Pillow`.
- django
- thumbnail
- imagefield
- thumbnails
Dynamic Thumbnail for `ImageField` with `Pillow`.
AdminImageWidget and AdminImageMixin to use easy_thumbnails in admin site forms for models with ImageField field.
You only have to put the code in some of your models.py and to have django-fiber installed in your system. Every image uploaded using Fiber admin dialog will be automatically resized and thumbnailed. Or whatever you need to do with it.
PushPinImageField is a Django form field that is a sub-class of an ImageField. The field accepts an image to upload and based on certain settings, notably the size of the resulting image, the sizes and colors of 3 different borders, as well as the color of the push pin, a re-sized image is created with a colorized push pin in the top-center. A live demo of the field as well as more detailed usage instructions are available as a [blog entry](http://www.robmisio.com/blog/2/).
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.
It gets the thumbnail picture url from a youtube video url. Example <img src="{{vide.url|youthumbnail:'s'}}"/> It supports 2 sizes small(s) and large (l)
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"
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...
You can specyfy max width and height which image can have, and it never exceed that size.
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.
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
Based on http://www.djangosnippets.org/snippets/192/ But this works with Django 1.1 while maintaining the same functionality.
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)
**General notes:** - Set MEDIA_URL (or whatever you use for uploaded content to point to S3 (ie. MEDIA_URL = "http://s3.amazonaws.com/MyBucket/")) - Put django-storage in project_root/libraries, or change the paths to make you happy. - This uses the functionality of django-storage, but *not* as DEFAULT_FILE_STORAGE. The functionality works like so: **Getting stuff to S3** - On file upload of a noted model, a copy of the uploaded file is saved to S3. - On any thumbnail generation, a copy is also saved to S3. **On a page load:** 1. We check to see if the thumbnail exists locally. If so, we assume it's been sent to S3 and move on. 2. If it's missing, we check to see if S3 has a copy. If so, we download it and move on. 3. If the thumb is missing, we check to see if the source image exists. If so, we make a new thumb (which uploads itself to S3), and move on. 4. If the source is also missing, we see if it's on S3, and if so, get it, thumb it, and push the thumb back up, and move on. 5. If all of that fails, somebody deleted the image, or things have gone fubar'd. **Advantages:** - Thumbs are checked locally, so everything after the initial creation is very fast. - You can clear out local files to save disk space on the server (one assumes you needed S3 for a reason), and trust that only the thumbs should ever be downloaded. - If you want to be really clever, you can delete the original source files, and zero-byte the thumbs. This means very little space cost, and everything still works. - If you're not actually low on disk space, Sorl Thumbnail keeps working just like it did, except your content is served by S3. **Problems:** - My python-fu is not as strong as those who wrote Sorl Thumbnail. I did tweak their code. Something may be wonky. YMMV. - The relative_source property is a hack, and if the first 7 characters of the filename are repeated somewhere, step 4 above will fail. - Upload is slow, and the first thumbnailing is slow, because we wait for the transfers to S3 to complete. This isn't django-storage, so things do genuinely take longer.
Example mixin for creating and removing thumbnails on a model. Also adds some methods for accessing an url for an image size. It might be a better idea to use a custom image field instead of this approach. Idea for getting the image url for different sizes from http://code.google.com/p/django-photologue Example usage <pre> >>> p.get_small_image_url() u'http://127.0.0.1:8000/site_media/photos/small_someimage.jpg' </pre>
29 snippets posted so far.