Skip to main content

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.

Usage

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):
    img.crop(int(l),int(t),int(r),int(b))
    return img

t = make_transformer(b, resizer, cropper)
i = t(i)
i.save(filename="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.

Project details


Download files

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

Source Distribution

boxmath-0.1.2.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file boxmath-0.1.2.tar.gz.

File metadata

  • Download URL: boxmath-0.1.2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for boxmath-0.1.2.tar.gz
Algorithm Hash digest
SHA256 360a2174183e830030c81ba547222baed89373c03be1b49fb380b63cdbe1be19
MD5 17f9b28e995ffbf2749777a0c2531a56
BLAKE2b-256 743a1a4d1765d09e48e45adcdbfd665b0a62db98a42a726e384faf1551c44ac2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page