https://github.com/Moresl/snapimg
高效图片压缩工具 | Fast image compressor with PNG/JPEG/WebP/AVIF support. Local processing, no upload.
https://github.com/Moresl/snapimg
avif compression-tool docker fastapi image-compression image-compressor image-optimization image-optimizer pngquant privacy react self-hosted shadcn-ui tailwindcss typescript vite web-app webp
Last synced: 7 days ago
JSON representation
高效图片压缩工具 | Fast image compressor with PNG/JPEG/WebP/AVIF support. Local processing, no upload.
- Host: GitHub
- URL: https://github.com/Moresl/snapimg
- Owner: Moresl
- License: mit
- Created: 2025-12-15T07:53:21.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-17T09:06:26.000Z (22 days ago)
- Last Synced: 2026-03-17T23:50:33.593Z (22 days ago)
- Topics: avif, compression-tool, docker, fastapi, image-compression, image-compressor, image-optimization, image-optimizer, pngquant, privacy, react, self-hosted, shadcn-ui, tailwindcss, typescript, vite, web-app, webp
- Language: Python
- Homepage: https://img.biekanle.com/
- Size: 1.72 MB
- Stars: 10
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-shadcn-ui - Link - 12-15 | (Platforms)
README
SnapImg
快速、注重隐私的在线图片压缩工具
支持 PNG、JPEG、WebP、AVIF 格式,70%+ 压缩率同时保持画质
English | 中文
---
> **为什么选择 SnapImg?** 图片完全在内存中处理,不保存到磁盘,不上传到第三方。你的图片隐私由你掌控。支持 Docker 一键部署到自己的服务器。
## 相关项目
本项目有两个版本,满足不同使用场景:
| 版本 | 描述 | 开源地址 |
|------|------|----------|
| **网页版** | 当前项目,基于 React + FastAPI 的在线压缩工具 | [snapimg](https://github.com/Moresl/snapimg) |
| **软件版** | 基于 Python + PyQt5 的桌面应用 | [ImageMinify](https://github.com/Moresl/ImageMinify) |
## 功能特点
- **多格式支持** - 支持 PNG、JPEG、WebP、AVIF 格式输入输出
- **高压缩率** - PNG 使用 pngquant/imagequant 算法,压缩率可达 70%+
- **保持质量** - 智能压缩算法,最大程度保留图片质量
- **本地处理** - 图片在服务器内存中处理,不保存到磁盘
- **批量压缩** - 单次最多处理 20 张图片
- **效果对比** - 滑动对比压缩前后效果
- **深色模式** - 支持浅色/深色主题切换
## 压缩原理
## 截图


## 技术栈
**前端:**
- React 19 + TypeScript
- Tailwind CSS + Shadcn UI
- Vite
**后端:**
- FastAPI + Python
- Pillow + imagequant + pngquant
- 纯内存处理,无数据库
## 快速开始
### Docker 部署(推荐)
```bash
# 构建镜像
docker build -t snapimg .
# 运行容器
docker run -d -p 80:80 --name snapimg snapimg
```
访问 http://localhost 即可使用。
### 本地开发
**前端:**
```bash
# 安装依赖
npm install
# 启动开发服务器
npm run dev
```
**后端:**
```bash
cd serve
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 安装依赖
pip install -r requirements.txt
# 启动服务
python main.py
```
## 项目结构
```
snapimg/
├── src/ # 前端源码
│ ├── components/ # React 组件
│ │ ├── ui/ # Shadcn UI 组件
│ │ ├── UploadZone.tsx
│ │ └── ImageCompare.tsx
│ ├── lib/ # 工具函数
│ ├── App.tsx
│ └── main.tsx
├── serve/ # 后端服务
│ ├── app/
│ │ ├── api/ # API 路由
│ │ ├── core/ # 核心压缩逻辑
│ │ └── models/ # 数据模型
│ └── requirements.txt
├── Dockerfile # Docker 构建文件
└── docker-compose.yml
```
## API 接口
### POST /api/compress/single
压缩单张图片。
**请求:** `multipart/form-data`
- `file`: 图片文件
- `format`: 输出格式 (original/png/jpeg/webp/avif)
**响应:**
```json
{
"filename": "image.png",
"original_size": 1024000,
"compressed_size": 307200,
"compression_ratio": 70.0,
"format": "png",
"data": "data:image/png;base64,...",
"success": true
}
```
## 与同类工具对比
| 特性 | SnapImg | TinyPNG | Squoosh |
|------|---------|---------|---------|
| 可自部署 | ✅ | ❌ | ❌ |
| 隐私保护 | ✅ 纯内存处理 | ❌ 上传到第三方 | ✅ 浏览器端 |
| 批量压缩 | ✅ 20 张 | ✅ 20 张 | ❌ 单张 |
| AVIF 支持 | ✅ | ❌ | ✅ |
| 效果对比 | ✅ 滑动对比 | ❌ | ✅ |
| Docker 部署 | ✅ 一键部署 | ❌ | ❌ |
| 开源免费 | ✅ MIT | ❌ 付费 API | ✅ |
## 贡献
欢迎贡献代码!请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详情。
我们提供了标准化的 Issue 模板,你可以方便地:
- 🐛 [报告 Bug](https://github.com/Moresl/snapimg/issues/new?template=bug_report.yml)
- ✨ [建议功能](https://github.com/Moresl/snapimg/issues/new?template=feature_request.yml)
- ❓ [提出问题](https://github.com/Moresl/snapimg/issues/new?template=question.yml)
## 许可证
[MIT License](LICENSE)
## Star History
如果觉得有用,请给个 ⭐ 支持一下!
[](https://www.star-history.com/#Moresl/snapimg&type=date)