图片缩放居中裁剪 图片缩放居中裁剪 @param file 图片文件 @param width 图片宽度 @param height 图片高度 @return err 错误
(file string, width, height int)
| 361 | // @param height 图片高度 |
| 362 | // @return err 错误 |
| 363 | func CropImage(file string, width, height int) (err error) { |
| 364 | var img image.Image |
| 365 | img, err = imaging.Open(file) |
| 366 | if err != nil { |
| 367 | return |
| 368 | } |
| 369 | ext := strings.ToLower(filepath.Ext(file)) |
| 370 | switch ext { |
| 371 | case ".jpeg", ".jpg", ".png", ".gif": |
| 372 | img = imaging.Fill(img, width, height, imaging.Center, imaging.CatmullRom) |
| 373 | default: |
| 374 | err = errors.New("unsupported image format") |
| 375 | return |
| 376 | } |
| 377 | return imaging.Save(img, file) |
| 378 | } |
| 379 | |
| 380 | // 采集HTML并把相对链接和相对图片 |
| 381 | // 内容类型,contType:0表示markdown,1表示html,2表示文本 |
nothing calls this directly
no outgoing calls
no test coverage detected