Skip to content

Commit 458a74a

Browse files
committed
Docs
1 parent 7115778 commit 458a74a

File tree

11 files changed

+1273
-1
lines changed

11 files changed

+1273
-1
lines changed

.github/workflows/docs.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Deploy Documentation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
deploy-docs:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v5
17+
- name: Deploy to GitHub Pages
18+
run: uvx mkdocs gh-deploy --force

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
example.jpg
22
dist/
33
.coverage
4+
site

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Django easy images
23

34
Easily build responsive HTML `<img>` tags by thumbnailing Django images using the VIPS fast image processing library.
@@ -38,7 +39,23 @@ INSTALLED_APPS = [
3839
# ...
3940
]
4041
```
42+
Since this uses pyvips, you'll need to have the [libvips library installed on your system](https://www.libvips.org/install.html).
43+
44+
## Documentation
45+
46+
Project documentation is built using [mkdocs](https://www.mkdocs.org/). To build and serve the documentation locally:
47+
48+
```bash
49+
pip install mkdocs
50+
mkdocs serve
51+
```
52+
53+
Then open http://localhost:8000 in your browser.
4154

55+
The documentation includes:
56+
- Usage examples
57+
- API reference
58+
- Configuration options
4259
Since this uses pyvips, you'll need to have the [libvips library installed on your system](https://www.libvips.org/install.html).
4360

4461
<table>

docs/advanced-usage.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Advanced Usage
2+
3+
## Queue Management
4+
5+
### Building Images
6+
7+
Images are built either:
8+
9+
1. Via cron job running `build_img_queue`
10+
2. Or via task runner using the `queued_img` signal
11+
12+
### Manual Queueing
13+
14+
Queue images manually using the `queue` method:
15+
16+
```python
17+
from easy_images import Img
18+
from my_app.models import Product
19+
20+
thumbnail = Img(width=300)
21+
thumbnail.queue(Product, fields=['main_image'])
22+
```
23+
24+
### Automatic Queueing
25+
26+
Automatically queue images when a FileField is saved using [signals](#signals):
27+
28+
```python
29+
from django.apps import AppConfig
30+
from my_app.images import thumbnail
31+
32+
class MyAppConfig(AppConfig):
33+
def ready(self):
34+
from my_app.models import Profile
35+
thumbnail.queue(Profile, build="src")
36+
```
37+
38+
## Performance Tips
39+
40+
1. For high-traffic sites, use `build="src"` to generate base images immediately
41+
2. Set up Celery for distributed image processing
42+
3. Use `format="webp"` for best compression/performance balance
43+
4. Limit `densities` to `[2]` unless high-DPI support is critical (or turn it off entirely)
44+
5. Consider pre-generating common image sizes during deployment
45+
46+
## Signals
47+
48+
### `file_post_save`
49+
Triggered when a FileField is saved. Use to automatically queue images:
50+
51+
```python
52+
from django.apps import AppConfig
53+
from my_app.images import thumbnail
54+
55+
class MyAppConfig(AppConfig):
56+
def ready(self):
57+
from my_app.models import Profile
58+
thumbnail.queue(Profile, build="src")
59+
```
60+
61+
### `queued_img`
62+
Triggered when images need building. Use with Celery:
63+
64+
```python
65+
from easy_images.management.process_queue import process_queue
66+
from easy_images.signals import queued_img
67+
68+
@app.task
69+
def build_img_queue():
70+
process_queue()
71+
72+
# In apps.py:
73+
queued_img.connect(lambda **kwargs: build_img_queue.delay(), weak=False)
74+
```
75+

docs/api.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# API Reference
2+
3+
## Core Modules
4+
5+
### `easy_images.core`
6+
7+
Main functionality for image processing with these key classes:
8+
9+
#### `Img` - Image Configuration
10+
```python
11+
from easy_images import Img
12+
13+
# Basic usage
14+
img = Img(width=800, format='webp', quality=85)
15+
processed_img = img(my_model.image_field)
16+
17+
# Chaining configurations
18+
responsive_img = (
19+
Img(width=1200)
20+
.extend(width=800, sizes={'768': 600, '480': 400})
21+
)
22+
23+
# Automatic processing on model save
24+
img.queue(MyModel) # Processes all ImageFields on MyModel
25+
```
26+
27+
#### `ImageBatch` - Batch Processing
28+
```python
29+
from easy_images import ImageBatch
30+
31+
batch = ImageBatch()
32+
img1 = batch.add(source_file=model1.image_field, options={'width': 800})
33+
img2 = batch.add(source_file=model2.image_field, options={'width': 600})
34+
35+
# Get HTML for all images
36+
html1 = img1.as_html()
37+
html2 = img2.as_html()
38+
```
39+
40+
#### `BoundImg` - Processed Image
41+
```python
42+
# Get image URLs
43+
main_url = processed_img.base_url()
44+
srcset = processed_img.srcset # List of available sizes
45+
46+
# Build images immediately (instead of queue)
47+
processed_img.build('all') # Options: 'all', 'base', 'srcset'
48+
```
49+
50+
### `easy_images.engine`
51+
Image processing engine implementation
52+
53+
### `easy_images.models`
54+
Database models for storing image information
55+
56+
## Management Commands
57+
58+
### `build_img_queue`
59+
Processes pending images in the queue:
60+
```bash
61+
python manage.py build_img_queue
62+
```
63+
64+
## Template Tags
65+
66+
### `easy_images`
67+
Template tags for rendering processed images:
68+
```html
69+
{% load easy_images %}
70+
71+
<!-- Basic usage -->
72+
{% easy_image obj.image_field width=800 %}
73+
74+
<!-- With responsive sizes -->
75+
{% easy_image obj.image_field width=1200 sizes="(max-width: 768px) 600px, (max-width: 480px) 400px" %}
76+
```

docs/configuration.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Configuration Options
2+
3+
## Image Processing Options
4+
5+
### `width`
6+
Limit the width of the image. Can be:
7+
8+
- Integer (pixels)
9+
- Tailwind size string: "xs", "sm", "md", "lg", "screen-sm", "screen-md", "screen-lg", "screen-xl", "screen-2xl"
10+
11+
```python
12+
Img(width=300) # Fixed width
13+
Img(width="md") # Responsive width
14+
```
15+
16+
### `ratio`
17+
The aspect ratio of the image. Can be:
18+
19+
- Float (e.g. `4/5`)
20+
- String: "square", "video" (16/9), "video_vertical", "golden", "golden_vertical"
21+
22+
```python
23+
Img(ratio="square") # 1:1 ratio
24+
Img(ratio=16/9) # Custom ratio
25+
```
26+
27+
### `crop`
28+
How to crop the image:
29+
30+
- `True` (default): Crop from center (0.5, 0.5)
31+
- `False`: Don't crop (use CSS object-fit instead)
32+
- Tuple: (x%, y%) crop position
33+
- String: Position keywords like "tl", "tr", "bl", "br", "l", "r", "t", "b"
34+
35+
```python
36+
Img(crop="tl") # Crop from top-left
37+
Img(crop=False) # No cropping
38+
```
39+
40+
### `quality`
41+
Image compression quality (default: 80)
42+
43+
```python
44+
Img(quality=90) # Higher quality
45+
```
46+
47+
## Advanced Options
48+
49+
### `sizes`
50+
Responsive sizes for different media queries:
51+
52+
```python
53+
Img(
54+
width=300,
55+
sizes={
56+
"print": {"width": 450, "quality": 90},
57+
800: 100 # Max-width 800px
58+
}
59+
)
60+
```
61+
62+
### `format`
63+
`srcset` image format (default: "webp"):
64+
65+
- "webp" (recommended)
66+
- "avif" (memory intensive)
67+
- "jpeg"
68+
69+
```python
70+
Img(format="avif") # Use AVIF format
71+
```
72+
73+
### `focal_window`
74+
Zoom area specified as (x1%, y1%, x2%, y2%):
75+
76+
```python
77+
Img(focal_window=(25, 25, 75, 75)) # Zoom center 50% of image
78+
```
79+
80+
### `densities`
81+
Higher density versions to generate (default: `[2]`):
82+
83+
```python
84+
Img(densities=[1.5, 2, 3]) # Generate 1.5x, 2x and 3x versions
85+
```

docs/getting-started.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Getting Started
2+
3+
## Installation
4+
5+
```bash
6+
pip install django-easy-images
7+
```
8+
9+
Add to your Django settings:
10+
```python
11+
INSTALLED_APPS = [
12+
"easy_images",
13+
# ...
14+
]
15+
```
16+
17+
### Dependencies
18+
You'll need [libvips](https://www.libvips.org/install.html) installed:
19+
20+
- **MacOS**: `brew install vips`
21+
- **Ubuntu**: `sudo apt-get install --no-install-recommends libvips`
22+
- **Arch**: `sudo pacman -S libvips`
23+
24+
## Basic Usage
25+
26+
### Using the Img class
27+
```python
28+
from easy_images import Img
29+
30+
# Create an image configuration
31+
thumb = Img(width="md")
32+
33+
# Generate HTML for an image
34+
html = thumb(profile.photo, alt="Profile photo").as_html()
35+
```
36+
37+
If you're going to be building several images, consider using the [`ImageBatch`](api.md#imagebatch) class to process them in bulk.
38+
39+
### Using template tags
40+
```html
41+
{% load easy_images %}
42+
43+
<!-- Basic usage -->
44+
{% img report.image width="md" alt="" %}
45+
46+
<!-- With predefined Img instance -->
47+
{% img report.image thumb alt="" %}
48+
```
49+
50+
## Next Steps
51+
- [Configuration Options](configuration.md)
52+
- [Advanced Usage](advanced-usage.md)

docs/index.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Django Easy Images Documentation
2+
3+
Welcome to the documentation for Django Easy Images - a powerful image processing solution for Django projects.
4+
5+
## What is Django Easy Images?
6+
7+
Django Easy Images makes it simple to:
8+
9+
- Generate responsive HTML `<img>` tags
10+
- Automatically create thumbnails and optimized versions
11+
- Queue image processing for better performance
12+
- Support modern formats like WebP and AVIF
13+
14+
## Quick Start
15+
16+
```python
17+
from easy_images import Img
18+
19+
# Create a thumbnail configuration
20+
profile_thumb = Img(width=200, ratio="square")
21+
22+
# Generate HTML for a profile photo
23+
html = profile_thumb(user.profile.photo, alt="User profile").as_html()
24+
```
25+
26+
## Documentation Sections
27+
28+
1. [Getting Started](getting-started.md) - Installation and basic usage
29+
2. [Configuration](configuration.md) - All available image processing options
30+
3. [Advanced Usage](advanced-usage.md) - Signals, queue management and performance tips
31+
4. [API Reference](api.md) - Detailed technical documentation
32+
33+
## Need Help?
34+
35+
Found an issue or have questions? Please [open an issue](https://github.com/your-repo/issues) on GitHub.

mkdocs.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
site_name: Django Easy Images
2+
3+
nav:
4+
- Getting Started: getting-started.md
5+
- Configuration: configuration.md
6+
- Advanced Usage: advanced-usage.md
7+
- API Reference: api.md
8+
9+
theme:
10+
name: mkdocs
11+
12+
markdown_extensions:
13+
- admonition
14+
- codehilite

0 commit comments

Comments
 (0)