MCPcopy Create free account
hub / github.com/TruthHun/BookStack / CropImage

Function CropImage

utils/util.go:363–378  ·  view source on GitHub ↗

图片缩放居中裁剪 图片缩放居中裁剪 @param file 图片文件 @param width 图片宽度 @param height 图片高度 @return err 错误

(file string, width, height int)

Source from the content-addressed store, hash-verified

361// @param height 图片高度
362// @return err 错误
363func 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表示文本

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected