# image-processor **Repository Path**: Jobs_Torvalds/image-processor ## Basic Information - **Project Name**: image-processor - **Description**: Golang图片处理 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-20 - **Last Updated**: 2026-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # img-processor High-performance CLI image processing tool written in Go. Supports Resize, Crop, Rotate, and Convert. ## Features - **Format Support**: JPG, PNG, GIF. - **Operations**: - `resize`: Resize maintaining aspect ratio. - `crop`: Center crop or coordinate-based crop. - `rotate`: Arbitrary angle rotation. - **Cross-Platform**: Built for Linux (AMD64 & ARM64). ## Usage ### 1. Simple Flags ```bash ./img-processor -input photo.jpg -output photo.webp -ops "resize:800,600|rotate:90" ``` ### 2. JSON Input ```bash ./img-processor -i '{"input":"photo.jpg", "actions":[{"action":"resize", "params":[800,600]}, {"action":"crop", "params":[100,100]}]}' ``` The tool outputs a JSON response to stdout: ```json {"status": "success", "path": "/abs/path/to/photo.webp", "message": ""} ``` ## Build & Package (打包构建) No CGO required. You can build for multiple platforms directly from your development environment. ### 1. Windows (AMD64) Run in PowerShell: ```powershell $env:CGO_ENABLED=0; go build -ldflags "-s -w" -o dist/img-processor-windows-amd64.exe . ``` ### 2. Linux (AMD64) Run in PowerShell: ```powershell $env:CGO_ENABLED=0; $env:GOOS='linux'; $env:GOARCH='amd64'; go build -ldflags "-s -w" -o dist/img-processor-linux-amd64 . ``` ### 3. Linux (ARM64) Run in PowerShell: ```powershell $env:CGO_ENABLED=0; $env:GOOS='linux'; $env:GOARCH='arm64'; go build -ldflags "-s -w" -o dist/img-processor-linux-arm64 . ``` > **Note**: The `-ldflags "-s -w"` flags strip debug information to reduce binary size. --- ## Verification (测试验证) ### General Usage All binaries support the same flags. Ensure you give execution permissions on Linux (`chmod +x`). The following examples assume: - Windows Binary: `.\img-processor.exe` - Linux Binary: `./img-processor` - Test Images: `img0001.jpg`, `fp1.jpg` ### 1. Resize (缩放) **CLI (-ops)** Width only (auto height): ```powershell # Windows .\img-processor.exe -input img0001.jpg -output out_resize_w.jpg -ops "resize:200" # Linux ./img-processor -input img0001.jpg -output out_resize_w.jpg -ops "resize:200" ``` Width & Height: ```powershell .\img-processor.exe -input img0001.jpg -output out_resize_wh.jpg -ops "resize:200,200" ``` **JSON (-i)** ```powershell # Windows (PowerShell quoting) .\img-processor.exe -i '{"input":"img0001.jpg", "output":"out_json_resize.jpg", "actions":[{"action":"resize", "params":[150,150]}]}' # Linux (Bash) ./img-processor -i '{"input":"img0001.jpg", "output":"out_json_resize.jpg", "actions":[{"action":"resize", "params":[150,150]}]}' ``` --- ### 2. Crop (裁剪) **CLI (-ops)** Center Crop: ```powershell .\img-processor.exe -input fp1.jpg -output out_crop_center.png -ops "crop:300,300" ``` Coordinate Crop (x, y, w, h): ```powershell .\img-processor.exe -input fp1.jpg -output out_crop_coord.jpg -ops "crop:10,10,200,200" ``` **JSON (-i)** ```powershell # Windows .\img-processor.exe -i '{"input":"fp1.jpg", "output":"out_json_crop.jpg", "actions":[{"action":"crop", "params":[300,300]}]}' ``` --- ### 3. Rotate (旋转) **CLI (-ops)** ```powershell .\img-processor.exe -input img0001.jpg -output out_rotate.jpg -ops "rotate:90" ``` **JSON (-i)** ```powershell .\img-processor.exe -i '{"input":"img0001.jpg", "output":"out_json_rotate.jpg", "actions":[{"action":"rotate", "params":[180]}]}' ``` --- ### 4. Combined / Pipeline (组合操作) **CLI (-ops)** Resize then Rotate: ```powershell .\img-processor.exe -input img0001.jpg -output out_pipeline.jpg -ops "resize:400|rotate:45" ``` **JSON (-i)** Crop then Resize: ```powershell # Windows .\img-processor.exe -i '{"input":"fp1.jpg", "output":"out_json_pipeline.jpg", "actions":[{"action":"crop", "params":[0,0,500,500]}, {"action":"resize", "params":[100,100]}]}' ``` --- ### 5. Format Conversion (格式转换) Convert to PNG: ```powershell .\img-processor.exe -input img0001.jpg -output out_convert.png -ops "resize:100" ``` Convert to GIF: ```powershell .\img-processor.exe -input fp1.jpg -output out_convert.gif -ops "resize:100" ```