将图像原点调整为指定大小。
django-resized的Python项目详细描述
将图像原点调整为指定大小。与sorl缩略图兼容。
功能
- 在Django 1.8、1.9、1.10和1.11上测试
- python 3支持
安装
pip install django-resized
配置(可选)
settings.py
DJANGORESIZED_DEFAULT_SIZE = [1920, 1080] DJANGORESIZED_DEFAULT_QUALITY = 75 DJANGORESIZED_DEFAULT_KEEP_META = True DJANGORESIZED_DEFAULT_FORCE_FORMAT = 'JPEG' DJANGORESIZED_DEFAULT_FORMAT_EXTENSIONS = {'JPEG': ".jpg"} DJANGORESIZED_DEFAULT_NORMALIZE_ROTATION = True
用法
models.py
from django_resized import ResizedImageField class MyModel(models.Model): ... image1 = ResizedImageField(size=[500, 300], upload_to='whatever') image2 = ResizedImageField(size=[100, 100], crop=['top', 'left'], upload_to='whatever') image3 = ResizedImageField(size=[100, 100], crop=['middle', 'center'], upload_to='whatever') image4 = ResizedImageField(size=[500, 300], quality=75, upload_to='whatever') image5 = ResizedImageField(size=[500, 300], upload_to='whatever', force_format='PNG')
选项
- size-最大宽度和高度,例如[640480]
- crop-调整大小并裁剪。['top','left']-左上角,['middle','center']是中心裁剪,['bottom','right']-裁剪右下角。
- quality-重定大小图像的质量1..100
- keep_meta-保留exif和其他元数据,默认为true
- force_format-强制调整大小的图像的格式,可用格式是pillow支持的格式,默认为none
如何运行测试
pip install tox tox