Skip to content

Thumbnail post creation signal #144

selwin opened this Issue May 7, 2012 · 1 comment

2 participants

selwin commented May 7, 2012

Hi Chris,

I'm trying to optimize the generated thumbnails and wrote a custom processor as per your suggestion in #28 but the final save_image function called in seems to defeat the optimization.

This is the processor that I tried:

import md5
import os
import subprocess

from PIL import Image

def optimize(image, **kwargs):
    An easy_thumbnails processor which uses jpegoptim to optimize thumbnails.
    Because jpegoptim doesn't have python bindings, we write the image to a 
    temporary directory, run jpegoptim over it and read it back.
    is_transparent = (image.mode == 'RGBA' or (image.mode == 'P' and 'transparency' in
    # Only optimize files without transparency
    if not is_transparent:
        name = ''/tmp/temp_image'), "JPEG")
        result = subprocess.Popen('jpegoptim {0}'.format(name), shell=True)
        image =
    return image

Using this picture as an example, creating a 104x69 thumbnail produce the following filesizes:

  • Original: 48K
  • After jpegoptim (in the optimize processor): 2.5k
  • The final generated thumbnail: 6.1K

What do you think of implementing a signal that gets called every time a thumbnail gets generated? With this signal we can run the final generated thumbnails through jpegoptim or other image optimization services.

Or is there a better way to do it?


You're right, it may be easiest to just have a post-creation signal. I've got no problem with that going in there. We even have a file to put it in now :)

Idea accepted!

Add the signal and a test then pull request.

@SmileyChris SmileyChris added a commit that closed this issue May 8, 2012
@SmileyChris Add a thumbnail_created signal
Thanks Selwin Ong! Fixes #144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.