1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
thumb.go 924 Bytes
一键复制 编辑 原始数据 按行查看 历史
package xcmd
import (
"errors"
"fmt"
)
// 生成缩略图,画质较低
//
// input 输入图片的路径
// output 输出图片的路径
// size 缩略图大小
func Thumb(input, output string, size uint) error {
if err := CheckCommand("convert"); err != nil {
return err
}
if size == 0 {
return errors.New("缩略图大小不能为0")
}
_, err := Exec(GetCommand("convert"), "-sample", fmt.Sprintf("%dx%d!", size, size), "-quality", "20", input, output)
return err
}
// 生成缩略图
//
// 和Thumb的区别为此处使用的-resize参数进行生成,效率稍慢,画质较高
func ThumbResize(input, output string, size uint) error {
if err := CheckCommand("convert"); err != nil {
return err
}
if size == 0 {
return errors.New("缩略图大小不能为0")
}
_, err := Exec(GetCommand("convert"), "-resize", fmt.Sprintf("%dx%d!", size, size), "-quality", "20", input, output)
return err
}
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.11

搜索帮助

53164aa7 5694891 3bd8fe86 5694891