This page is READ-ONLY. It is generated from the old site.
All timestamps are relative to 2013 (when this page is generated).
If you are looking for TeX support, please go to VietTUG.org

Crop and scale image to a given size

django snippets
Added by bronzeboyvn almost 2 years ago

http://djangosnippets.org/snippets/224/

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.


Comments

Added by bronzeboyvn over 1 year ago

dòng 28 phải là:

y_offset = float(src_height - crop_height) / 2