8000 fiddling with options and updating docs · pygeek/django-thumbnail@3c8f195 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c8f195

Browse files
committed
fiddling with options and updating docs
1 parent 34344c8 commit 3c8f195

File tree

6 files changed

+78
-17
lines changed

6 files changed

+78
-17
lines changed

docs/reference/settings.rst

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ Features
6060
* More dependencies
6161
* Requires a little extra work to transfer data between environments
6262

63+
``THUMBNAIL_KEY_DBCOLUMN``
64+
==========================
65+
66+
- Default ``'key'``
67+
68+
Since MSSQL reserved the ``key`` name for db columns you can change this to
69+
something else using this setting.
70+
6371

6472
``THUMBNAIL_ENGINE``
6573
====================
@@ -90,17 +98,34 @@ Pgmagick
9098
* It is a tad slow?
9199
* Can handle CMYK sources
92100

93-
ImageMagick
94-
-----------
101+
ImageMagick / GraphicsMagick
102+
----------------------------
95103
``'sorl.thumbnail.engines.convert_engine.Engine'``. This engine uses the
96-
ImageMagick ``convert`` command. Features:
104+
ImageMagick ``convert`` or GraphicsMagic ``gm convert`` command. Features:
97105

98106
* Easy to install
99107
* Produces high quality images
100108
* It is pretty fast
101109
* Can handle CMYK sources
102110
* It is a command line command, that is less than ideal,
103111

112+
``THUMBNAIL_CONVERT``
113+
====================
114+
115+
- Default ``'convert'``
116+
117+
Path to convert command, use ``'gm convert'`` for GraphicsMagick.
118+
Only applicable for the convert Engine.
119+
120+
121+
``THUMBNAIL_IDENTIFY``
122+
====================
123+
124+
- Default ``'identify'``
125+
126+
Path to identify command, use ``'gm identify'`` for GraphicsMagick.
127+
Only applicable for the convert Engine.
128+
104129

105130
``THUMBNAIL_STORAGE``
106131
=====================
@@ -145,7 +170,7 @@ The port for Redis server. Only applicable for the Redis Key Value Store
145170
``THUMBNAIL_CACHE_TIMEOUT``
146171
===========================
147172

148-
- Default: ``sys.maxint``
173+
- Default: ``3600 * 24 * 365 * 10``
149174

150175
Cache timeout for Cached DB Key Value Store. You should probably keep this at
151176
maximum or ``None`` if your caching backend can handle that as infinite.
@@ -204,6 +229,13 @@ Should we upscale by default? ``True`` means we upscale images by default.
204229
Default thumbnail quality. A value between 0 and 100 is allowed. This can be
205230
overridden by individual options.
206231

232+
``THUMBNAIL_PROGRESSIVE``
233+
========================
234+
235+
- Default: ``True``
236+
237+
Saves jpeg thumbnails as progressive jpegs. This can be overridden by individual
238+
options.
207239

208240
``THUMBNAIL_DUMMY``
209241
===================
@@ -215,7 +247,7 @@ case is when you want to do development on a deployed project that has image
215247
references in its database. Instead of downloading all the image files from the
216248
server hosting the deployed project and all its thumbnails we just set this
217249
option to ``True``. This will generate placeholder images for all thumbnails
218-
regardless of the input source.
250+
missing input source.
219251

220252

221253
``THUMBNAIL_DUMMY_SOURCE``
@@ -231,7 +263,7 @@ option is for example ``http://placehold.it/%(width)sx%(height)s``.
231263
``THUMBNAIL_DUMMY_RATIO``
232264
=========================
233265

234-
Default: ``1.5``
266+
- Default: ``1.5``
235267

236268
This option is only applicable if ``THUMBNAIL_DUMMY`` is set to true. This
237269
value sets an image ratio to all thumbnails that are not defined by width

docs/template.rst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,32 @@ Upscale is a boolean and controls if the image can be upscaled or not. For
129129
example if your source is 100x100 and you request a thumbnail of size 200x200
130130
and upscale is False this will return a thumbnail of size 100x100. If upscale
131131
was True this would result in a thumbnail size 200x200 (upscaled). The default
132-
value is True.
132+
value is ``True``.
133133

134134
``quality``
135135
^^^^^^^^^^^
136136
Quality is a value between 0-100 and controls the thumbnail write quality.
137-
Default value is 95.
137+
Default value is ``95``.
138+
139+
``progressive``
140+
^^^^^^^^^^^^^^^
141+
This controls whether to save jpeg thumbnails as progressive jpegs. Default
142+
value is ``True``.
143+
144+
``orientation``
145+
^^^^^^^^^^^^^^^
146+
This controls whether to orientate the resulting thumbnail with respect to the
147+
source EXIF tags for orientation. Default value is ``True``.
138148

139149
``format``
140150
^^^^^^^^^^
141-
This controls the write format and thumbnail extension. Formats supported
142-
by the shipped engines are JPEG and PNG. Default value is JPEG.
151+
This controls the write format and thumbnail extension. Formats supported by
152+
the shipped engines are ``'JPEG'`` and ``'PNG'``. Default value is ``'JPEG'``.
143153

144154
``colorspace``
145155
^^^^^^^^^^^^^^
146-
This controls the resulting thumbnails color space, valid values are: RGB and
147-
GRAY. Default value is RGB
156+
This controls the resulting thumbnails color space, valid values are: ``'RGB'``
157+
and ``'GRAY'``. Default value is ``'RGB'``.
148158

149159
``options``
150160
^^^^^^^^^^^

sorl/thumbnail/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sorl.thumbnail.conf import settings
1+
from sorl.thumbnail.conf import settings, defaults as default_settings
22
from sorl.thumbnail.helpers import tokey, serialize
33
from sorl.thumbnail.images import ImageFile
44
from sorl.thumbnail import default
@@ -24,6 +24,11 @@ class ThumbnailBackend(object):
2424
'crop': False,
2525
}
2626

27+
extra_options = (
28+
('progressive', 'THUMBNAIL_PROGRESSIVE'),
29+
('orientation', 'THUMBNAIL_ORIENTATION'),
30+
)
31+
2732
def get_thumbnail(self, file_, geometry_string, **options):
2833
"""
2934
Returns thumbnail as an ImageFile instance for file with geometry and
@@ -33,6 +38,13 @@ def get_thumbnail(self, file_, geometry_string, **options):
3338
source = ImageFile(file_)
3439
for key, value in self.default_options.iteritems():
3540
options.setdefault(key, value)
41+
# For the future I think it is better to add options only if they
42+
# differ from the default settings as below. This will ensure the same
43+
# filenames beeing generated for new options at default.
44+
for key, attr in self.extra_options:
45+
value = getattr(settings, attr)
46+
if value != getattr(default_settings, attr):
47+
options.setdefault(key, value)
3648
name = self._get_thumbnail_filename(source, geometry_string, options)
3749
thumbnail = ImageFile(name, default.storage)
3850
cached = default.kvstore.get(thumbnail)

sorl/thumbnail/conf/defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
# Save as progressive when saving as jpeg
6464
THUMBNAIL_PROGRESSIVE = True
6565

66+
# Orientate the thumbnail with respect to source EXIF orientation tag
67+
THUMBNAIL_ORIENTATION = True
68+
6669
# This means sorl.thumbnail will generate and serve a generated dummy image
6770
# regardless of the thumbnail source content
6871
THUMBNAIL_DUMMY = False

sorl/thumbnail/engines/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#coding=utf-8
2+
from sorl.thumbnail.conf import settings
23
from sorl.thumbnail.helpers import toint
34
from sorl.thumbnail.parsers import parse_crop
45

@@ -21,7 +22,7 @@ def orientation(self, image, geometry, options):
2122
"""
2223
Wrapper for ``_orientation``
2324
"""
24-
if options.get('orientation', True):
25+
if options.get('orientation', settings.THUMBNAIL_ORIENTATION):
2526
return self._orientation(image)
2627
return image
2728

@@ -66,7 +67,7 @@ def write(self, image, options, thumbnail):
6667
format_ = options['format']
6768
quality = options['quality']
6869
# additional non-default-value options:
69-
progressive = options.get('progressive')
70+
progressive = options.get('progressive', settings.THUMBNAIL_PROGRESSIVE)
7071
raw_data = self._get_raw_data(image, format_, quality,
7172
progressive=progressive
7273
)
@@ -103,7 +104,7 @@ def is_valid_image(self, raw_data):
103104

104105
def _orientation(self, image):
105106
"""
106-
Read orientation exif data and orientate the image accordningly
107+
Read orientation exif data and orientate the image accordingly
107108
"""
108109
return image
109110

sorl/thumbnail/engines/convert_engine.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def write(self, image, options, thumbnail):
2222
Writes the thumbnail image
2323
"""
2424
handle, out = mkstemp(suffix='.%s' % EXTENSIONS[options['format']])
25-
if options['format'] == 'JPEG' and options.get('progressive'):
25+
if (
26+
options['format'] == 'JPEG' and
27+
options.get('progressive', settings.THUMBNAIL_PROGRESSIVE)
28+
):
2629
image['options']['interlace'] = 'line'
2730
args = settings.THUMBNAIL_CONVERT.split(' ')
2831
args.append(image['source'])

0 commit comments

Comments
 (0)
0