def generate_thumb(img, thumb_size, format):

    img.seek(0)  # see http://code.djangoproject.com/ticket/8222 for details
    image = Image.open(img)

    # Convert to RGB if necessary
    if image.mode not in ('L', 'RGB', 'RGBA'):
        image = image.convert('RGB')

    # get size
    thumb_w, thumb_h = thumb_size
    # If you want to generate a square thumbnail
    if thumb_w == thumb_h:
        xsize, ysize = image.size
        minsize = min(xsize, ysize)
        xnewsize = (xsize - minsize) / 2
        ynewsize = (ysize - minsize) / 2
        image2 = image.crop(
            (xnewsize,
                ynewsize,
                xsize - xnewsize,
                ysize - ynewsize))
        image2.load()
        image2.thumbnail(thumb_size, Image.ANTIALIAS)
    else:
        image2 = image
        image2.thumbnail(thumb_size, Image.ANTIALIAS)

    io = cStringIO.StringIO()
    if format.upper() == 'JPG':
        format = 'JPEG'
    elif format.upper() == 'TIF':
        format = 'TIFF'
    image2.save(io, format)
    return ContentFile(io.getvalue())
Calculate and set the x and y ranges.
dataset/ETHPy150Open jamiecurle/django-omblog/omblog/fields.py/generate_thumb--crossover with--dataset/ETHPy150Open bokeh/bokeh/bokeh/charts/builder.py/XYBuilder.set_ranges