Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 982 Bytes

File metadata and controls

33 lines (25 loc) · 982 Bytes

About

Modifies reddit's image cropping algorithm to accept an image of any dimension to produce a square thumbnail. This is sometimes referred to as smart-cropping.

Produces an NxN-sized thumbnail of an image without distortion. For example, a 100px x 50px image can be converted to a 25px x 25px thumbnail. First, the 100x50 will be cropped to 50x50, then reduced to 25x25. The cropping algorithm works by calculating the entropy of an image and slicing off the side that has the least entropy.

Dependencies

You'll need PIL installed to modify images. http://www.pythonware.com/products/pil/

Usage

from PIL import Image
import pycrop as pc

im = Image.open(path_to_file)
image = pc.prepare_image(im, (200,200))
image.save(new_filename, 'JPEG')

Functions

prepare_image(Image, (x, y))

Takes a PIL Image object and a tuple of the dimensions.