| Line | |
|---|
| 1 | ========= |
|---|
| 2 | Thumbnail |
|---|
| 3 | ========= |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | The `thumbnail` module provides thumbnail creation, given an image file. |
|---|
| 7 | |
|---|
| 8 | Width and/or height can be given for the thumbnail to be created. If one is |
|---|
| 9 | not given, the thumbnail size is generated at the best fit to keep the scale. |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | Let's import the method:: |
|---|
| 13 | |
|---|
| 14 | >>> from thumbnail import generate |
|---|
| 15 | |
|---|
| 16 | Let's check the sample image size:: |
|---|
| 17 | |
|---|
| 18 | >>> from thumbnail import image_size |
|---|
| 19 | >>> image_size(image_filename) |
|---|
| 20 | (241, 600) |
|---|
| 21 | |
|---|
| 22 | And 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 | |
|---|
| 29 | Let'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) |
|---|