root / cachers / doc / thumbnail.txt

Revision 139:5c9b7a2c2dee, 0.9 kB (checked in by Tarek Ziad?? <tarek@…>, 13 months ago)

caching images with resize

Line 
1=========
2Thumbnail
3=========
4
5
6The `thumbnail` module provides thumbnail creation, given an image file.
7
8Width and/or height can be given for the thumbnail to be created. If one is
9not given, the thumbnail size is generated at the best fit to keep the scale.
10
11
12Let's import the method::
13
14    >>> from thumbnail import generate
15
16Let's check the sample image size::
17
18    >>> from thumbnail import image_size
19    >>> image_size(image_filename)
20    (241, 600)
21
22And try the thumbnail generation over it::
23
24    >>> th1 = generate(image_filename, scale=0.5)
25    >>> th2 = generate(image_filename, width=32)
26    >>> th3 = generate(image_filename, height=64)
27    >>> th4 = generate(image_filename, width=12, height=15)
28
29Let's control the results::
30
31    >>> from StringIO import StringIO
32    >>> image_size(StringIO(th1))
33    (120, 298)
34    >>> image_size(StringIO(th2))
35    (32, 79)
36    >>> image_size(StringIO(th3))
37    (25, 62)
38    >>> image_size(StringIO(th4))
39    (12, 29)
Note: See TracBrowser for help on using the browser.