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

Function ImageCopy

graphics/copy.go:11–27  ·  view source on GitHub ↗
(src image.Image, x, y, w, h int)

Source from the content-addressed store, hash-verified

9)
10
11func ImageCopy(src image.Image, x, y, w, h int) (image.Image, error) {
12
13 var subImg image.Image
14
15 if rgbImg, ok := src.(*image.YCbCr); ok {
16 subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.YCbCr) //图片裁剪x0 y0 x1 y1
17 } else if rgbImg, ok := src.(*image.RGBA); ok {
18 subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.RGBA) //图片裁剪x0 y0 x1 y1
19 } else if rgbImg, ok := src.(*image.NRGBA); ok {
20 subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.NRGBA) //图片裁剪x0 y0 x1 y1
21 } else {
22
23 return subImg, errors.New("图片解码失败")
24 }
25
26 return subImg, nil
27}
28
29func ImageCopyFromFile(p string, x, y, w, h int) (src image.Image, err error) {
30 file, err := os.Open(p)

Callers 1

ImageCopyFromFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected