Built-in Filters

Sore Thumb comes with a number of built-in filters, which will fit most of your thumbnail requirements.

Default Filters

The default filters perform image scaling, cropping, transparency and miscellaneous effects.

You can import the default filters with the following:

from sorethumb.filters.defaultfilters import *
class sorethumb.filters.defaultfilters.FixedHeightFilter(height, no_upscale=False)

Resizes the image to the specified height respecting the aspect ratio

Parameters:
  • height – New height in pixels
  • no_upscale – If True the image will only be scaled down
class sorethumb.filters.defaultfilters.FixedWidthFilter(width, no_upscale=False)

Resizes the image to the specified width respecting the aspect ratio

Parameters:
  • width – New width
  • no_upscale – If True the image will only be scaled down
class sorethumb.filters.defaultfilters.GrayscaleFilter(*args, **kwargs)

Converts the image to grayscale

class sorethumb.filters.defaultfilters.InvertFilter(*args, **kwargs)

Inverts the colours in the image

class sorethumb.filters.defaultfilters.MaskFilter(mask_path)

Replaces the alpha channel with a new image

Parameters:
  • mask_path – Path to mask image
class sorethumb.filters.defaultfilters.OpacityFilter(opacity=0.5)

Sets the alpha channel to a given opacity

Parameters:
  • opacity – A floating point value between 0 and 1, where 0
class sorethumb.filters.defaultfilters.OpaqueFilter(col)

Renders an image with an alpha channel on to an opaque background

Parameters:
  • col – The colour of the background as an HTML string or tuple
class sorethumb.filters.defaultfilters.OverlayFilter(overlay_path)

Renders a translucent image over the image

Parameters:
  • overlay_path – System path to the overlay image
class sorethumb.filters.defaultfilters.RectangularCropFilter(ratio)

Crops an image to the specified x/y ratio

Parameters:
  • ratio – New aspect ratio for the image
class sorethumb.filters.defaultfilters.ResizeCanvasFilter(width, height, background_color='#000', background_opacity=255)

Adjusts the canvas size and centers the image.

Parameters:
  • width – Width of resized version
  • height – Height of resized version
  • background_color – Color for the canvas background
  • background_opacity – Opacity for canvas background (255 is opaque)
class sorethumb.filters.defaultfilters.ResizeFilter(width, height)

Resizes an image to new dimensions (may change the aspect ratio

Parameters:
  • width – The required width of the thumbnail
  • height – The required height of the thumbnail
class sorethumb.filters.defaultfilters.SquareFilter(*args, **kwargs)

Crops an image to be square (from center)

class sorethumb.filters.defaultfilters.ThumbnailFilter(width, height)

Uses PIL’s thumbnail method to reduce an image.

Parameters:
  • width – The maximum width of the thumbnail
  • height – The maximum height of the thumbnail
class sorethumb.filters.defaultfilters.VerticalGradientFilter(col1, col2)

Renders a vertical gradient from colour 1 to colour 2

Parameters:
  • col1 – The colour at the top of the image
  • col2 – The colour at the bottom of the image

Draw Filters

Filters in the drawfilters module have an extra dependancy on aggdraw.

Import the default filters with the following:

You can import the default filters with the following:

from sorethumb.filters.drawfilters import *

Filters which require the aggdraw module to work

class sorethumb.filters.drawfilters.RoundedCornerFilter(radius, border=None)

Rounds the corners of an image with a given radius, and optionally draws a border.

Parameters:
  • radius – The radius for the corners
  • border – The border color as HTML string or tuple

Table Of Contents

Previous topic

Welcome to Sore Thumb’s documentation!

This Page