Image cropping plugin, can be directly applied to django admin.
Project description
简介
上传图片文件时,不同的场景,对图片的宽高有着不同的需求,而django
自带的控件ImageField
,无法对图片进行裁剪处理,导致上传的图片可能不符合需求。因此,为方便开发,我自定义了一个拥有图片裁剪、上传功能的django
控件ImageCropField
。
ImageCropField
继承了ImageField
的同时,集成了图片裁剪插件cropper.js。你仅需进行简单的配置,就可以非常方便的将ImageCropField
与ModelForm
、admin
进行搭配使用。
安装
-
使用以下命令安装django-image-crop:
pip install django-image-crop
-
安装依赖库pillow(图形处理库)
pip install pillow
配置
-
在配置文件setting.py中引入
django-image-crop
setting.py
INSTALLED_APPS = [ ... 'image_crop' ]
-
配置media路径与路由
setting.py
MEDIA_URL = "/media/" MEDIA_ROOT = BASE_DIR / "media"
urls.py*
from django.conf import settings from django.urls import re_path from django.views.static import serve urlpatterns = [ ... re_path(r'media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}) ]
使用
model.py
from django.db import models
from image_crop import ImageCropField
class ImageCrop(models.Model):
image = ImageCropField(blank=True, upload_to="images", verbose_name='上传图片')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-image-crop-0.0.2.tar.gz
(90.4 kB
view details)
File details
Details for the file django-image-crop-0.0.2.tar.gz
.
File metadata
- Download URL: django-image-crop-0.0.2.tar.gz
- Upload date:
- Size: 90.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c3852533d76089c688c52e5c6c64b947d3c002fb8623146b0b0911db5dd8047 |
|
MD5 | be2876d8c6062b818684c87d163c3bda |
|
BLAKE2b-256 | b449038775a78382457cf7326306206f133a8e077403cc8b46d3a7b3c9ad1779 |