django-var-cms provides three complementary media capabilities out of the box: modal previews for any file field in list and detail views, a built-in image cropper with rotate and flip support, and a file conversion API that can transform images, audio, video, and PDF files — all without leaving the control panel.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-var-cms/llms.txt
Use this file to discover all available pages before exploring further.
Modal Previews
No configuration is needed. When a model field is anImageField, the list view renders a thumbnail and clicking it opens a full-size preview modal. When a field is a FileField, an icon link is rendered; clicking it opens the appropriate modal player based on the file extension.
The icon and modal type are determined by the file extension using the following map:
| Extension | Icon | Modal behaviour |
|---|---|---|
mp4, webm | video icon | Inline <video> player |
mp3, wav | music icon | Inline <audio> player |
pdf | file-text icon | Embedded PDF viewer |
| Any other extension | paperclip icon | Opens/downloads in new tab |
VarCMSModelAdmin:
Image Cropper
EveryImageField widget in add/edit forms includes a built-in cropper modal powered by Cropper.js on the frontend and Pillow on the backend. Users can:
- Draw a custom crop box
- Rotate the image by arbitrary degrees
- Flip horizontally and/or vertically
- Choose an output format (JPEG, PNG, or WebP)
MEDIA_ROOT/crops/ with a 12-character UUID hex filename and its URL is returned to the frontend to update the form field.
Transform Order
When multiple transforms are applied, they are executed in this order:- Flip —
scale_x = -1flips horizontally;scale_y = -1flips vertically - Rotate — rotation is applied with
expand=Trueso the full image is preserved - Crop — the crop box
(x, y, w, h)is applied to the transformed image
Crop API Endpoint
multipart/form-data (standard POST body).
| Parameter | Type | Required | Description |
|---|---|---|---|
file_path | string | ✅ | Relative media path of the source image (e.g. var_cms/images/2024/06/photo.jpg) |
x | float → int | ✅ | Left edge of the crop box in pixels |
y | float → int | ✅ | Top edge of the crop box in pixels |
w | float → int | ✅ | Width of the crop box in pixels |
h | float → int | ✅ | Height of the crop box in pixels |
rotate | float | ❌ | Rotation in degrees (default 0) |
scale_x | float | ❌ | -1 to flip horizontally, 1 for no flip (default 1) |
scale_y | float | ❌ | -1 to flip vertically, 1 for no flip (default 1) |
format | string | ❌ | Output format: jpeg, png, or webp (defaults to source format) |
200 OK):
size array reflects the dimensions of the cropped image ([width, height]). JPEG output automatically converts RGBA images to RGB.
The crop endpoint is protected by
login_required. Unauthenticated requests are redirected to the login page. Cropped images are saved under MEDIA_ROOT/crops/ and are given a 12-character UUID hex filename to avoid collisions.Media Conversion API
The conversion endpoint can transform images between formats, convert audio and video files via ffmpeg, and rasterise PDF pages to PNG images via pdf2image.| Parameter | Type | Required | Description |
|---|---|---|---|
file_path | string | ✅ | Relative media path of the source file |
target_fmt | string | ✅ | Desired output extension, e.g. webp, mp3, mp4, png |
Supported Conversions
- Images (Pillow)
- Audio & Video (ffmpeg)
- PDF to Images (pdf2image)
Image-to-image conversion is handled entirely by Pillow — no external binaries required.Supported formats:
jpeg / jpg, png, webp, bmp, tiff, gifAny combination of these formats can be converted to any other. Images in RGBA or palette (P) mode are automatically converted to RGB when the target is JPEG. Converted images are saved with quality=90.Success response:MEDIA_ROOT/converted/ with 12-character UUID hex filenames.
Requirements
| Capability | Requirement | How to install |
|---|---|---|
| Image previews & cropping | Pillow | pip install pillow (included in standard install) |
| Image format conversion | Pillow | Already required |
| Audio / video conversion | ffmpeg binary | sudo apt install ffmpeg |
| PDF to images | pdf2image + poppler | pip install pdf2image + sudo apt install poppler-utils |