Jj's web stream

Sepia images with Django, Python and Sorl-thumbnail

Picture side by side of a toy in color and sepiia

Meet Sorl-sepia, a Sorl engine backend (PIL only so far) to turn your images into sepia tones. See the README file for instructions.

The interesting trick about sepia images is that they are just gray-scale pictures with a different color palette. In this case the sepia color I'm using is #FFF0C0.

Doing this on PIL is quite straight forward (from effbot's blog):

# You have your PIL Image instance on a 'im' variable

# Convert it to grayscale
im = im.convert('L') # L mode means gray-scale

# Set the sepia palette
im.putpalette(linear_ramp) # will explain this later

# Make RGB again
im = im.convert('RGB')

And there you have it. Now the linear_ramp variable. It is actually a map of 256 blocks indicating what color to use for each of the possible gray-scale values (white to black). You can see the original blog post on how to build the linear_ramp.

If you just want to turn your images to gray-scale instead of sepia, set sorl-sepia SORL_DEFAULT_SEPIA_TONE setting to (0, 0, 0).