یک API سبک و سریع برای فشردهسازی و تغییر اندازه تصاویر
A lightweight & fast API for image compression and resizing
| فارسی | English |
|---|---|
| فشردهسازی تصاویر با کیفیت قابل تنظیم | Adjustable quality image compression |
| تغییر اندازه با الگوریتم LANCZOS | High-quality resize using LANCZOS |
| پشتیبانی از JPEG، PNG و AVIF | Supports JPEG, PNG and AVIF |
| مستندات زیبا با Scalar | Beautiful API docs with Scalar |
| ساختار تمیز و قابل توسعه | Clean and extensible architecture |
| تکنولوژی / Technology | نسخه / Version |
|---|---|
| Python | ≥ 3.12 |
| FastAPI | ≥ 0.141 |
| Pillow | ≥ 12.3 |
| uv | Package Manager |
git clone https://github.com/binarysecrets-ir/binarysecrets_api.git
cd binarysecrets_apiuv syncuv run uvicorn main:app --reloadسرور روی آدرس زیر در دسترس خواهد بود:
The server will be available at:
http://127.0.0.1:8000
مستندات تعاملی با Scalar در آدرس زیر قابل مشاهده است:
Interactive documentation powered by Scalar is available at:
http://127.0.0.1:8000/scalar
POST /image/compress
| نام / Name | نوع / Type | توضیح / Description | پیشفرض / Default |
|---|---|---|---|
image |
File | فایل تصویر (multipart/form-data) | - |
config |
JSON String | تنظیمات فشردهسازی به صورت Form | - |
{
"quality": 85,
"width": 1280,
"height": 720,
"out_format": "AVIF"
}quality: عدد بین ۱ تا ۱۰۰ / Integer between 1 and 100widthوheight: اختیاری / Optional (if not provided, original size is kept)out_format: یکی ازJPEG،PNG،AVIF
curl -X POST "http://127.0.0.1:8000/image/compress" \
-F "image=@photo.jpg" \
-F 'config={"quality":80,"width":800,"height":600,"out_format":"AVIF"}' \
--output compressed.avifbinarysecrets_api/
├── main.py # نقطه ورود FastAPI / FastAPI entry point
├── models.py # مدلهای Pydantic / Pydantic models
├── utils/
│ └── images.py # منطق پردازش تصویر / Image processing logic
├── static/
│ └── standalone.js # فایل Scalar / Scalar standalone file
├── pyproject.toml
└── uv.lock
کلاس ImageProcessor با استفاده از الگوی Strategy، انکودرهای مختلف را مدیریت میکند:
The ImageProcessor class uses the Strategy pattern to manage different encoders:
JPEGEncoderPNGEncoderAVIFEncoder
این طراحی باعث میشود اضافه کردن فرمتهای جدید بسیار ساده باشد.
This design makes adding new formats very easy.
- تصاویر نامعتبر با خطای
406برگردانده میشوند.
Invalid images return a406error. - تصاویر RGBA هنگام تبدیل به JPEG به صورت خودکار به RGB تبدیل میشوند.
RGBA images are automatically converted to RGB when saving as JPEG. - Resize فقط زمانی انجام میشود که
widthوheightمشخص شده باشند.
Resize only happens when bothwidthandheightare provided.
اگر ایده یا باگی پیدا کردی، خوشحال میشم Pull Request یا Issue باز کنی.
Feel free to open an Issue or Pull Request if you find a bug or have an idea.
این پروژه در حال حاضر لایسنس مشخصی ندارد.
This project currently has no specific license.
اگر میخوای لایسنس اضافه بشه، بگو.
Let me know if you'd like to add a license.
ساخته شده با ❤️ توسط BinarySecrets
Made with ❤️ by BinarySecrets