MCPcopy Index your code
hub / github.com/TruthHun/BookStack / cropScreenshot

Function cropScreenshot

utils/util.go:320–355  ·  view source on GitHub ↗
(selector, jsonFile, pngFile string)

Source from the content-addressed store, hash-verified

318}
319
320func cropScreenshot(selector, jsonFile, pngFile string) (images map[string]map[int]string) {
321 ele := strings.Split(selector, ",")
322 images = make(map[string]map[int]string)
323 b, err := ioutil.ReadFile(jsonFile)
324 if err != nil {
325 beego.Error(err.Error())
326 return
327 }
328 info := &ScreenShotInfo{}
329 if err = json.Unmarshal(b, info); err != nil {
330 beego.Error(err.Error())
331 return
332 }
333
334 if len(ele) != len(info.Data) {
335 return
336 }
337
338 img, err := imaging.Open(pngFile)
339 if err != nil {
340 beego.Error(err.Error())
341 return
342 }
343
344 for idx, item := range info.Data {
345 ele[idx] = strings.TrimSpace(ele[idx])
346 images[ele[idx]] = make(map[int]string)
347 for idx2, item2 := range item {
348 imgItem := imaging.Crop(img, image.Rect(int(item2.X), int(item2.Y), int(item2.X+item2.Width), int(item2.Y+item2.Height)))
349 saveName := fmt.Sprintf(pngFile+"-%v-%v.png", idx, idx2)
350 imaging.Save(imgItem, saveName)
351 images[ele[idx]][idx2] = saveName
352 }
353 }
354 return
355}
356
357// 图片缩放居中裁剪
358// 图片缩放居中裁剪

Callers 1

CrawlByChromeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected