Goimgrz(Go Image Resize)是一款基于Golang开发的,命令行下针对图片URL资源、文件,进行图片缩放处理的命令行工具,支持图片目录扫描、文件名过滤、文件缩放方式、插值处理等功能!
Github地址:https://github.com/tkstorm/goimgrz
1. 特性
- Local文件、url图像资源文件调整大小,支持指定宽度和高度设置;
- 扫描本地文件目录图像并调整其大小;
- 图像文件大小,名称过滤;
- Resize插值函数规范;
- Jpeg质量设置;
- 支持批量和并发图像调整大小处理;
2. 安装
go get -v github.com/tkstorm/goimgrz/cmd/goimgrz
3. 命令行帮助
$ goimgrz -h
Usage of goimgrz:
-crawler_url string
the crawler url used by girls download the http images and resize only matched image files
-dir string
scan the dir where image inside to be resize
-dst string
the output dir where image after resize store (default "/tmp/goimgrz")
-height uint
set resize image's height
-img string
the local image file which to be resize
-imgs string
local image files which to be resize, separated by ','
-interp uint
the provided interpolation functions support (from fast to slow execution time), 0:NearestNeighbor,1:Bilinear,2:Bicubic,3:MitchellNetravali,4:Lanczos2,5:Lanczos3
-name string
using shell pattern to filter image, like *.png (default "*")
-quality int
set resize image's quality percent (default 75)
-size string
using file size to filter image, like +200k
-url string
the image's http(s) url to be resize, image resource(url|urls|img|imgs|dir) at least need set one
-urls string
image's http(s) urls to be resize, separated by ','
-verbose
append water image
-water_img string
append water image
-width uint
set resize image's width, default width and height is 0 represent origin image
4. 使用简单
$ goimgrz -img ./testdata/gopher2018.png -width 400
2019/06/25 16:10:16 resize ok: /tmp/goimgrz/gopher2018.png (inputW=400,inputH=0)
$ goimgrz -dir ./testdata -width 500 -dst /tmp/goimgrz/500
2019/06/25 16:11:22 resize ok: /tmp/goimgrz/500/gopher2018.png (inputW=500,inputH=0)
2019/06/25 16:11:22 resize ok: /tmp/goimgrz/500/web_bg.jpg (inputW=500,inputH=0)
2019/06/25 16:11:23 resize ok: /tmp/goimgrz/500/IMG_2489.JPG (inputW=500,inputH=0)
$ goimgrz -urls https://cdn-images-1.medium.com/max/1600/1\*k74qnaAcJd3bzRj7PnLIbg.jpeg,https://cdn-images-1.medium.com/max/2600/0\*jraDH1ztolpSmT9I
2019/06/22 18:49:29 resize ok: /tmp/1*k74qnaAcJd3bzRj7PnLIbg.jpeg (inputW=300,inputH=0)
2019/06/22 18:49:30 resize ok: /tmp/0*jraDH1ztolpSmT9I (inputW=300,inputH=0)
$ goimgrz -url https://cdn-images-1.medium.com/max/1600/1\*n1kWgo0dPS80uoE430hqSQ.jpeg -width 300
2019/06/22 18:42:17 resize ok: /tmp/1*n1kWgo0dPS80uoE430hqSQ.jpeg (inputW=300,inputH=0)
$ goimgrz -img ./testdata/IMG_2489.JPG -width 500 -interp 2
2019/06/25 16:16:40 resize ok: /tmp/goimgrz/IMG_2489.JPG (inputW=500,inputH=0)
$ goimgrz -dir ./testdata -size +1M
2019/06/23 23:02:20 resize ok: /tmp/IMG_2489.JPG (inputW=300,inputH=0)
$ goimgrz -dir ./testdata -size -1M -name '*/*.png'
2019/06/23 23:08:22 resize ok: /tmp/gopher2018.png (inputW=300,inputH=0)
5. Todo
- Http请求超时设置
- Http代理设置(下载特殊网络图像时)
- Crawler url支持(当需要一个html页面的图像时)
- Short Param Support
- Concurrent资源设置(现在没有限制并发资源设置)
- More图像格式支持(现在只支持jpeg,png,gif)