Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Simple image box arithmetic

Project Description

This provides image crop/resize algorithm for chaining multiple resize, crop actions and producing a resulting crop/resize action pair.


The usage is fairly simple:

from boxmath import box, resize, crop, size, make_transformer
from wand import image

# Load the image to get its width and height
i = image.Image(filename="chrysanthemum.jpg")
b = box(i.width, i.height)

# manipulate the virtual image
b = resize(b, 629, 483)
b = crop(b, 0, 0, 480, 480)
b = resize(b, 1000, 1000)

# render
def resizer(img, w, h):
    img.resize(int(w), int(h), filter=FILTER)
    return img

def cropper(img, l,t,r,b):
    return img

t = make_transformer(b, resizer, cropper)
i = t(i)"chrysanthemum-1000x1000.jpg")

Normally, if we would of used wand or PIL directly, each resize would degrade the image. The action of down scaling and then up scaling would wreck the quality of the image; with the power of math, we only apply the resize and crop when we need render the image.

Not that the width, height, left, top, right, and bottom values passed to the resizer and cropper functions are cast as ints.

This is because they are either fractions.Fraction() instances or int(). boxmath uses the Fraction class to ensure precision while resizing and cropping.

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(9.2 kB) Copy SHA256 Hash SHA256
Source None Aug 6, 2013

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting