Removed spacial char

main
Arkadyuti Sarkar 2023-03-22 21:16:58 +05:30
parent d96ad46d45
commit 8ecf4b86ad
2 changed files with 14 additions and 1 deletions

View File

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

15
main.go
View File

@ -12,15 +12,17 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
)
//ffmpeg -i "tmp/${fName}" -c:v libvpx-vp9 -c:a libopus -s 640x360 -b:v 276k -minrate 138k -maxrate 400k -tile-columns 1 -threads 4 -quality good -crf 36 "tmp/${fName}.webm" 2> /dev/null
var finalWidth uint = 1920
var outPath = filepath.Join(".", "out")
var inputPath = filepath.Join(".", "assets")
func readArgs() {
fmt.Println(len(os.Args), os.Args)
if len(os.Args) == 4 {
inputPath = os.Args[1]
outPath = os.Args[2]
@ -56,6 +58,16 @@ func main() {
writeResult(results)
}
func removeSpacialCharFromString(src string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9-.]+")
if err != nil {
fmt.Println("regex err:", err)
}
processedString := reg.ReplaceAllString(src, "-")
return processedString
}
func handleFile(filePath string, results *[][]string) {
var individualResult = map[string]string{"fileName": filepath.Base(filePath), "success": "no", "resized": "no", "old": ""}
file, err := os.Open(filePath)
@ -110,6 +122,7 @@ func updateResult(results *[][]string, individualResult map[string]string) {
func resizeImage(filePath string, file *os.File, img image.Image, individualResult map[string]string) {
fileName := filepath.Base(file.Name())
fileName = removeSpacialCharFromString(fileName)
outFileName := outPath + "/" + fileName
individualResult["old"] = strconv.Itoa(img.Bounds().Dx()) + " x " + strconv.Itoa(img.Bounds().Dy())