djangosnippets.org: Latest snippets tagged with 'pil'http://djangosnippets.org/tags/pil/2016-12-29T10:30:09.721190-06:00Resize or Modify an image before saving
2016-12-29T10:30:09.721190-06:00asurahttp://djangosnippets.org/snippets/10597/<p>Small snippet that will resize all images before they uploaded to the server. </p>
Freely redistributableDownload an image using requests, resize it using PIL, and save it to a model ImageField.
2015-03-24T19:31:51.304922-05:00stewxhttp://djangosnippets.org/snippets/10473/<p>You can use this as a model method.</p>
Freely redistributableYet Another Image Resizer
2010-02-25T20:11:23.298721-06:00stephen_mcdhttp://djangosnippets.org/snippets/1944/<p>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.</p>
<ul>
<li>Only generates the …</li></ul>
Freely redistributableLoad Windows ICO files
2009-01-17T07:38:09.541368-06:00dchttp://djangosnippets.org/snippets/1287/<p>PIL IcoImagePlugin is twelve year old and it can't handle recent Windows ICO files. Here is a function that handles all ICO versions and preserve transparency.</p>
<p>Usage:</p>
<pre><code># Load biggest icon from file
image = load_icon('icon.ico')
# Save third icon as PNG
load_icon('icon.ico', 2).save('icon.png')
</code></pre>
Freely redistributableImage resize on demand
2008-12-29T03:21:12.071652-06:00VidJahttp://djangosnippets.org/snippets/1268/<p><strong> Image on demand view </strong></p>
<p>I often post photos on photography fora. Most fora want you to place a link to a photo somewhere on the net, but different fora have different rules. Some fora want you to stick to a maximum of 800 pixels wide, some 700 pixel and some …</p>
Freely redistributableUnsharp Mask with PIL and PythonMagick
2008-12-28T17:44:18.255770-06:00VidJahttp://djangosnippets.org/snippets/1267/<p><strong>A Magick PIL</strong></p>
<p>I used to do my image conversions with ImageMagick and system calls back in my PHP days. With Django PIL is the obvious choice for most image stuff, but frustrated by the lack of a proper unsharp mask function for PIL I found some code in the …</p>
Freely redistributableDynamic image generator
2008-12-02T22:19:05.724198-06:00pcholthttp://djangosnippets.org/snippets/1230/<p>This is the complete image_processor.py module, allowing you to add an image containing an arbitrary piece of text. I use this to label the horizontal axis of a skills-matrix report.</p>
<p>Credit www.renewtek.com for paying me to do this stuff!</p>
Freely redistributableresize to thumbnail with scale-to-fill
2008-09-30T17:57:01.280077-05:00rennathttp://djangosnippets.org/snippets/1100/<p><strong>So you can upload rectangular pictures but still have square thumbnails.</strong></p>
<p>"Scale to <strong>fill</strong>" instead of the out of the box "scale to <strong>fit</strong>" you get with <code>Image.thumbnail</code></p>
Freely redistributableResize image on save
2008-04-07T12:08:13.197737-05:00Davidhttp://djangosnippets.org/snippets/688/<p>This snippet is extracted from my Photo model. I use it to ensure that any uploaded image is constrained to a specified size (resized on save).</p>
<p>In my case, I don't need to maintain a "thumbnail" and "fullsize" version, so I just store the resized version to save space.</p>
Freely redistributableImageURLField for forms
2007-09-03T18:39:34.248050-05:00insinhttp://djangosnippets.org/snippets/402/<p>A URL field specifically for images, which can validate details about the filesize, dimensions and format of an image at a given URL, without having to read the entire image into memory.</p>
<p>Requires <a href="http://www.pythonware.com/library/pil/">Python Imaging Library</a>.</p>
<p><em>4th October, 2008</em> - updated for 1.0 compatibility.</p>
Freely redistributableFunction to create resized versions of an image from a URL and saving it to a local path
2007-02-28T15:48:37.413968-06:00obeattiehttp://djangosnippets.org/snippets/53/<p>This is a really useful function I used to create the resized preview images you can see on the <a href="http://www.obeattie.com/">homepage of my site</a>. Basically, it takes the original URL of an image on the internet, creates a resized version of that image by fitting it into the constraints specified …</p>
Freely redistributableSharpening images
2007-02-28T13:28:36.669646-06:00rajeshdhttp://djangosnippets.org/snippets/52/<p>Returns a sharpened copy of an image. </p>
<p>Resizing down or thumbnailing your images with PIL.Image tends to make them blurry. I apply this snippet to such images in order to regain some sharpness.</p>
Freely redistributable