Login

Snippets by rpw

Snippet List

Crop and scale image to a given size

Prerequisites: [Python Imaging Library](http://www.pythonware.com/products/pil/) This function scales a given image (provided as binary data in any format the PIL supports) to a specified size. If the force parameter is True, the function makes sure that the resulting image is exactly the specified size, cropping and scaling it as necessary (but never distorting it) to make sure the whole image area is filled out. If force is False, it simply uses the thumbnail function provided by the PIL, which preserves the image aspect ratio and does not increase the image dimensions beyond those of the original file, so you may not get an image that has the exact dimensions you specified. The result image is returned as JPEG data.

  • thumbnail
  • crop
  • scale
Read More
Author: rpw
  • 3
  • 22

rpw has posted 1 snippet.