{"id":30284193,"url":"https://github.com/hikarinagi/hips","last_synced_at":"2026-05-16T22:02:12.116Z","repository":{"id":307448384,"uuid":"1028872952","full_name":"Hikarinagi/hips","owner":"Hikarinagi","description":"real‑time image process service for Hikarinagi","archived":false,"fork":false,"pushed_at":"2025-07-31T09:26:04.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-31T11:17:31.599Z","etag":null,"topics":["gin","go","image-optimization","image-processing","image-resizing","libvips"],"latest_commit_sha":null,"homepage":"https://www.hikarinagi.org","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hikarinagi.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-30T07:28:04.000Z","updated_at":"2025-07-31T09:26:07.000Z","dependencies_parsed_at":"2025-07-31T11:21:25.975Z","dependency_job_id":"a04cbc8d-7ac4-4ab2-b48b-50c8091c75d4","html_url":"https://github.com/Hikarinagi/hips","commit_stats":null,"previous_names":["hikarinagi/hips"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Hikarinagi/hips","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hikarinagi%2Fhips","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hikarinagi%2Fhips/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hikarinagi%2Fhips/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hikarinagi%2Fhips/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hikarinagi","download_url":"https://codeload.github.com/Hikarinagi/hips/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hikarinagi%2Fhips/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270756349,"owners_count":24639867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gin","go","image-optimization","image-processing","image-resizing","libvips"],"created_at":"2025-08-16T19:00:52.596Z","updated_at":"2026-05-16T22:02:12.111Z","avatar_url":"https://github.com/Hikarinagi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"hikarinagi的图片处理服务(Hikarinagi Image Process Service)，[bimg](https://github.com/h2non/bimg) 负责核心的图片处理，[gin](https://github.com/gin-gonic/gin) 负责网络请求处理\n\n## 快速开始\n\n### 环境要求\n\n- Go 1.24+\n- libvips\n- Cloudflare R2 账户\n\n### 安装依赖\n\n```bash\nsudo apt install libvips-dev\nsudo yum install libvips-dev\nbrew install vips (For MacOS)\n```\n\n### 环境变量\n\n| 环境变量 | 描述 | 默认值 | 是否必须 |\n|---------|------|--------|----------|\n| `R2_ENDPOINT` | Cloudflare R2存储端点地址 | - | ✅ |\n| `R2_ACCESS_KEY` | R2访问密钥 | - | ✅ |\n| `R2_SECRET_KEY` | R2秘密密钥 | - | ✅ |\n| `R2_BUCKET` | R2存储桶名称 | - | ✅ |\n| `PORT` | 服务监听端口 | `8080` | ❌ |\n| `MAX_WORKERS` | 最大worker数量 | CPU核心数×2 | ❌ |\n| `MAX_QUEUE_SIZE` | 最大队列大小 | MAX_WORKERS×10 | ❌ |\n| `TASK_TIMEOUT` | 任务执行超时时间 | `30s` | ❌ |\n| `ENABLE_ASYNC` | 启用异步处理 | `true` | ❌ |\n| `BUFFER_SIZE` | 缓冲区大小 | `100` | ❌ |\n| `VIPS_CONCURRENCY` | libvips内部线程数 | CPU核心数 | ❌ |\n| `VIPS_CACHE_SIZE` | libvips操作缓存数量 | `200` | ❌ |\n| `VIPS_CACHE_MEM_MB` | libvips缓存内存限制(MB) | `256` | ❌ |\n| `NET_MAX_IDLE_CONNS` | 最大空闲连接数 | `100` | ❌ |\n| `NET_MAX_IDLE_CONNS_PER_HOST` | 每个host的最大空闲连接数 | `20` | ❌ |\n| `NET_MAX_CONNS_PER_HOST` | 每个host的最大连接数 | `50` | ❌ |\n| `NET_DIAL_TIMEOUT` | 连接超时时间 | `10s` | ❌ |\n| `NET_KEEP_ALIVE` | Keep-Alive时间 | `30s` | ❌ |\n| `NET_IDLE_CONN_TIMEOUT` | 空闲连接超时时间 | `90s` | ❌ |\n| `NET_REQUEST_TIMEOUT` | 整体请求超时时间 | `60s` | ❌ |\n| `NET_DISABLE_COMPRESSION` | 是否禁用压缩 | `false` | ❌ |\n| `CACHE_L1_ENABLED` | 启用L1内存缓存 | `true` | ❌ |\n| `CACHE_L2_ENABLED` | 启用L2 Redis缓存 | `true` | ❌ |\n| `CACHE_L3_ENABLED` | 启用L3磁盘缓存 | `true` | ❌ |\n| `CACHE_L1_MAX_MEMORY_MB` | L1最大内存限制(MB) | `1024` | ❌ |\n| `CACHE_L2_MAX_MEMORY_MB` | L2最大内存限制(MB) | `3072` | ❌ |\n| `CACHE_L3_MAX_DISK_GB` | L3最大磁盘空间(GB) | `10` | ❌ |\n| `REDIS_ADDR` | Redis服务器地址 | `localhost:6379` | ❌ |\n| `REDIS_PASSWORD` | Redis密码 | - | ❌ |\n| `REDIS_DB` | Redis数据库编号 | `0` | ❌ |\n| `CACHE_DISK_DIR` | 磁盘缓存目录 | `./cache` | ❌ |\n| `CACHE_PROMOTE_THRESHOLD` | 缓存提升访问次数阈值 | `3` | ❌ |\n| `CACHE_DEMOTE_THRESHOLD` | 缓存降级访问次数阈值 | `1` | ❌ |\n| `CACHE_SYNC_INTERVAL` | 缓存同步间隔 | `5m` | ❌ |\n| `THIRD_PARTY_PROVIDERS_JSON` | 第三方图片提供方列表(JSON数组) | - | ❌ |\n\n### 构建和运行\n\n```bash\n./scripts/build.sh\n# 或者直接构建\ngo build -o bin/hips cmd/server/main.go\n\n# 运行\n./bin/hips\n```\n\n## 使用方法\n\n### 图片处理\n\n```\nGET /{图片路径}?参数\n```\n\n支持的参数：\n- `w`: 宽度 (最大 2048px)\n- `h`: 高度 (最大 2048px)\n- `q`: 质量 (1-100，默认 85)\n- `f`: 格式 (jpeg/png/webp/avif)\n- `crop`: 裁剪模式 (fit/fill/crop)\n- `gravity`: 重心位置 (center/north/south/east/west)\n- `blur`: 模糊程度 (0-100，默认 0)\n\n示例：\n```\nhttp://localhost:8080/path/to/image.jpg?w=300\u0026h=200\u0026q=85\u0026f=webp\u0026blur=2\n```\n\n### 第三方图片处理\n\n通过配置第三方提供方后，可以直接请求远程图片地址：\n\n1) 配置环境变量（注意JSON需使用双引号）：\n\n```bash\nexport THIRD_PARTY_PROVIDERS_JSON='[{\"name\":\"bangumi\",\"allowed_hosts\":[\"lain.bgm.tv\"]}]'\n```\n\n2) 请求示例：\n\n```http\nGET /bangumi/https%3A%2F%2Flain.bgm.tv%2Fpic%2Fcover%2Fl%2F1c%2Fba%2F343241_TWFSN.jpg?w=600\u0026h=400\u0026f=avif\u0026q=85\n```\n\n说明：\n- 第一路径段为 `provider` 名称，对应 `name`\n- 第二段为远程图片完整URL，建议URL编码；服务端也会尝试解码\n- 仅当URL的 `host` 在对应 `allowed_hosts` 白名单中时才会拉取\n\n### 健康检查\n\n```\nGET /health\n```\n\n### 部署\n\n默认启用 `libvips` 的多线程处理，推荐部署在核心数不小于16，RAM不小于32GiB的实例上来达到最佳性能\n\n### 缓存\n\n- **L1 - 内存**: 最热门的图片，LRU策略，默认1GB\n- **L2 - Redis**: 比较热门的图片，默认3GB\n- **L3 - Disk**: 热门原图，默认10GB\n- **L4 - CDN**: 主要缓存层\n\n## 许可证\n\nAGPL-3.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhikarinagi%2Fhips","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhikarinagi%2Fhips","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhikarinagi%2Fhips/lists"}