jpg 打印

This commit is contained in:
admin
2026-02-24 18:51:53 +08:00
parent 9e141b8de0
commit e1e0ac8929
10 changed files with 535 additions and 127 deletions

View File

@@ -29,7 +29,7 @@ ESP32-S3 works as a Wi-Fi REST controller and replaces Android App logic:
- `GET /v1/printer/status`
- Print:
- `POST /v1/print/raster`
- `POST /v1/print/image` (`base64_msb_1bpp` or `base64_gray8`)
- `POST /v1/print/image` (direct JPEG binary upload, no base64)
- `POST /v1/print/qr`
- `POST /v1/print/text`
- `POST /v1/print/receipt`
@@ -101,7 +101,7 @@ The page provides:
- health/status check
- connect/disconnect printer
- submit a simple text print job
- upload an image (gray8 payload) and let ESP32-S3 handle threshold/scale/raster conversion
- upload a JPG image (binary payload) and let ESP32-S3 decode/threshold/scale/raster conversion
- view jobs list
If API key is enabled, input it in the page before invoking actions.
@@ -141,21 +141,17 @@ curl -X POST http://<esp-ip>/v1/print/raster \
}'
```
### Image print (gray8 auto-scale to 384)
### Image print (direct JPG upload, no base64)
```bash
curl -X POST http://<esp-ip>/v1/print/image \
-H 'Content-Type: application/json' \
-d '{
"width":800,
"height":600,
"encoding":"base64_gray8",
"data":"<BASE64_GRAY_BYTES>",
"scale_to_width":true,
"threshold":160,
"density":"中等"
}'
curl -X POST 'http://<esp-ip>/v1/print/image?scale_to_width=1&threshold=160&invert=0&max_height=2200&density=medium' \
-H 'Content-Type: image/jpeg' \
--data-binary @./sample.jpg
```
Request constraints:
- Request body limit: 4 MB
- Suggested image size: <= 3 MB when using built-in Web UI uploader
### QR print
```bash
curl -X POST http://<esp-ip>/v1/print/qr \
@@ -256,6 +252,8 @@ curl -X POST http://<esp-ip>/v1/ota/upgrade \
- BLE side is central/client role, not printer peripheral role.
- `base64_msb_1bpp` uses Android-compatible bit order (MSB first).
- `/v1/print/image` accepts raw `image/jpeg` bytes directly (no base64 wrapper).
- Large buffers for image upload/decode prefer PSRAM first, then fallback to internal RAM.
- `/v1/print/text` and `/v1/print/receipt` now support UTF-8 Chinese via embedded 16x16 GB2312 glyphs.
- Characters outside embedded glyph set are rendered as square fallback boxes.
- QR encoding uses embedded `qrcodegen` (Project Nayuki C implementation).