Ai
447 Star 3.2K Fork 1.2K

GVP进击的皇虫/BookStack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
copy.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
TruthHun 提交于 2018-02-22 15:19 +08:00 . 假装第一次提交
package graphics
import (
"errors"
"image"
"os"
"github.com/nfnt/resize"
)
func ImageCopy(src image.Image, x, y, w, h int) (image.Image, error) {
var subImg image.Image
if rgbImg, ok := src.(*image.YCbCr); ok {
subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.YCbCr) //图片裁剪x0 y0 x1 y1
} else if rgbImg, ok := src.(*image.RGBA); ok {
subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.RGBA) //图片裁剪x0 y0 x1 y1
} else if rgbImg, ok := src.(*image.NRGBA); ok {
subImg = rgbImg.SubImage(image.Rect(x, y, x+w, y+h)).(*image.NRGBA) //图片裁剪x0 y0 x1 y1
} else {
return subImg, errors.New("图片解码失败")
}
return subImg, nil
}
func ImageCopyFromFile(p string, x, y, w, h int) (image.Image, error) {
var src image.Image
file, err := os.Open(p)
if err != nil {
return src, err
}
defer file.Close()
src, _, err = image.Decode(file)
return ImageCopy(src, x, y, w, h)
}
func ImageResize(src image.Image, w, h int) image.Image {
return resize.Resize(uint(w), uint(h), src, resize.Lanczos3)
}
func ImageResizeSaveFile(src image.Image, width, height int, p string) error {
dst := resize.Resize(uint(width), uint(height), src, resize.Lanczos3)
return SaveImage(p, dst)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/truthhun/BookStack.git
git@gitee.com:truthhun/BookStack.git
truthhun
BookStack
BookStack
v1.3.1

搜索帮助