package fileop import ( "bytes" "fmt" "os/exec" "strconv" "github.com/h2non/bimg" ) func EncodeImageThumbnail(inputPath string, outputPath string, width, height int) error { buffer, err := bimg.Read(inputPath) if err != nil { return err } options := bimg.Options{ Width: width, Height: height, Embed: true, Type: bimg.JPEG, StripMetadata: true, } newImage, err := bimg.NewImage(buffer).Process(options) if err != nil { return err } return bimg.Write(outputPath, newImage) } func EncodeVideoThumbnail(inputPath string, outputPath string, width, _ int) error { args := []string{ "-i", inputPath, "-y", "-vframes", "1", "-q:v", "1", "-vf", "thumbnail,scale=" + strconv.Itoa(width) + ":-1", outputPath, } cmd := exec.Command("ffmpeg", args...) var b bytes.Buffer cmd.Stderr = &b if err := cmd.Run(); err != nil { return fmt.Errorf("%s; %w", b.String(), err) } return nil }